#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
const int M = 2e6+5, K = 605, N = 305;

int n,m,k,a[M],b[K],to[M],from[M],num[M];
int tp[N],bt[N],where[M],head[N];

vector<int> st[N];
priority_queue<pair<int,int> > Q;
vector<int> ep;
struct opr{
    int ty,s1,s2;
}ans[M*2];
int op = 0;

void putin(int i,int x) {
    where[i] = x;
    tp[x] = i;
    Q.push(P(to[i],x));
    if (st[x].size() == head[x]) bt[x] = i;
    st[x].push_back(i);
    // printf("1 %d\n",x);
    ans[++op] = opr{1,x,0};
}

void putpop(int i,int x) {
    // printf("1 %d\n",x);
    ans[++op] = opr{1,x,0};
    st[x].pop_back();
    if (st[x].empty()) {
        ep.push_back(x);
    }
    else {
        tp[x] = st[x].back();
        Q.push(P(to[tp[x]],x));
    }
}

int main() {
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    int T;
    cin >> T;
    while (T--) {
        scanf("%d%d",&n,&m,&k);
        for (int i = 1; i <= m; ++i) scanf("%d",&a[i]);

        memset(b,0,sizeof(b));
        memset(head,0,sizeof(head));

        for (int i = 1; i <= n; ++i) {
            while (!st[i].empty()) st[i].clear();
        }

        for (int i = 1; i <= m; ++i) {
            if (b[a[i]] == 0) {
                b[a[i]] = i;
                num[i] = 1;
            }
            else {
                to[b[a[i]]] = i;
                from[i] = b[a[i]];
                b[a[i]] = 0;
                num[i] = 0;
            }
        }

        for (int i = 1; i <= n; ++i) ep.push_back(i);

        for (int i = 1; i <= m; ++i) {
            if (num[i] == 1) {
                if (!ep.empty()) {
                    putin(i,ep.back());
                    ep.pop_back();
                }
                else {
                    P t;
                    while (!Q.empty()) {
                        t = Q.top();
                        if (to[tp[t.second]] == t.first) break;
                        Q.pop();
                    }
                    putin(i,t.second);
                }
            }

            else {
                int f = from[i], w = where[f];
                if (tp[w] == f) {
                    putpop(i,w);
                }
                else if (bt[w] == f && !ep.empty()) {
                    int e = ep.back();
                    // printf("1 %d\n",e);
                    ans[++op] = opr{1,e,0};
                    // printf("2 %d %d\n",w,e);
                    ans[++op] = opr{2,w,e};
                    bt[w] = st[w][++head[w]];
                    if (st[w].size() == head[w]) ep.push_back(w);
                }
                else {
                    if (!ep.empty()) {
                        putin(i,ep.back());
                        ep.pop_back();                       
                    }
                }
            }
        }
    }

    printf("%d\n",op);
    for (int i = 1; i <= op; ++i) {
        if (ans[i].ty == 1) printf("1 %d\n",ans[i].s1);
        else printf("2 %d %d\n",ans[i].s1,ans[i].s2);
    }
    
    return 0;
}