#include<bits/stdc++.h>
const int M = 2e6+7;
const int N = 600;
int n, m, k, a[M]; int e[M];
void slv(){
    for(int i=1; i<=m; i++)
        scanf("%d", a+i), a[i]--;
    printf("%d\n", 2*m);
    for(int i=1; i<=m; i++){
        if(e[a[i]] == 1) printf("1 %d\n", n), e[a[i]] = 0, e[a[i]^1] = e[a[i]^1]? 1:0;
        else if(e[a[i]] == 2) printf("1 %d\n", (a[i]>>1)+1), e[a[i]] = 0;
        else if(e[a[i]] == 0) printf("1 %d\n", (a[i]>>1)+1), e[a[i]] = e[a[i]^1]? 2:1;
        printf("2 %d %d\n", n, (a[i]>>1)+1);
    }
}
std::set<int> fkccf;
std::map<int, int> ban;
std::set<int> acc, ept;
std::deque<int> s[N];
int pos[N];
void slv1(){
    for(int i=1; i<=m; i++)
        scanf("%d", a+i);
    int lst = 1;
    for(int i=1; i<=m; i++){
        if(fkccf.count(a[i])) fkccf.erase(a[i]);
        else{
            fkccf.insert(a[i]);
            if(fkccf.size() == (n<<1)-1){
                ban[lst] = a[i+1];
                lst = i+1;
                //printf("=%d %d\n", lst, a[i+1]);
            }
        }
    }
    printf("%d\n", m*2);
    int bn = 1;
    for(int i=1; i<(n<<1); i++){
        pos[a[i]] = -1;
    }
    for(int i=1; i<=n; i++){
        acc.insert(i); ept.insert(i);
    }
    for(int i=1; i<=m; i++){
        if(pos[a[i]] == -1){
            pos[a[i]] = *acc.begin()==pos[bn]? *(++acc.begin()):*acc.begin();
            printf("1 %d\n", pos[a[i]]);
            s[pos[a[i]]].push_back(a[i]);
            if(s[pos[a[i]]].size() == 2) acc.erase(pos[a[i]]);
            else if(s[pos[a[i]]].size() == 1) ept.erase(pos[a[i]]);
            printf("2 1 2\n");
        }
        else{
            if(s[pos[a[i]]].size() == 1){
                printf("1 %d\n", pos[a[i]]);
                ept.insert(pos[a[i]]);
                s[pos[a[i]]].clear();
                pos[a[i]] = -1;
                printf("2 1 2\n");
            }
            else{
                if(s[pos[a[i]]][0] == a[i]){
                    printf("1 %d\n", *ept.begin());
                    printf("2 %d %d\n", *ept.begin(), pos[a[i]]);
                    acc.insert(pos[a[i]]);
                    pos[a[i]] = -1;
                }
                else{
                    printf("1 %d\n", pos[a[i]]);
                    acc.insert(pos[a[i]]);
                    pos[a[i]] = -1;
                    printf("2 1 2\n");
                }
            }
        }
    }
}
int T;
int main(){
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);
    scanf("%d", &T);
    while(T--){
        scanf("%d%d%d", &n, &m, &k);
        if(k == 2*n-2) slv();
        else slv1();
    }
    return 0;
}