#include <bits/stdc++.h>
using namespace std;
const int maxn=605;
const int maxk=(maxn<<1)+5;
const int maxm=2000005;
#define top asdfjk
int n,m,k,cnt,tot,ot[maxm<<1][2],a[maxm],pos[maxk],sta[maxn][3],top[maxn];
int L[maxk],R[maxk],vis[maxk],b[maxm],tmp[maxk];
#ifndef CHECK
#undef assert
#define assert(x) 0
#endif
inline void ins(int y)
{
    int x=n+2+top[y];
    R[y]=R[x],L[R[y]]=y,L[y]=x,R[x]=y;
}
inline void del(int x)
{
    R[L[x]]=R[x],L[R[x]]=L[x];
}
inline void oper1(int x,int a,bool t=false)
{
    // fprintf(stderr,"1 %d\n",x);
    ot[tot][0]=x,ot[tot][1]=-1,tot++,cnt++;
    assert(1<=x && x<=n);
    if(top[x]>=0 && sta[x][top[x]]==a) top[x]--;
    else assert(top[x]<=1),sta[x][++top[x]]=a;
    if(!t && top[x]==2) assert(false);
    del(x),ins(x);
}
inline void oper2(int x,int y)
{
    int i;
    // fprintf(stderr,"2 %d %d\n",x,y);
    ot[tot][0]=x,ot[tot][1]=y,tot++;
    assert(1<=x && x<=n && 1<=y && y<=n && x!=y),
    assert(top[x]>=0 && top[y]>=0 && sta[x][0]==sta[y][0]);
    for(i=0;i<top[x];i++) sta[x][i]=sta[x][i+1];
    for(i=0;i<top[y];i++) sta[y][i]=sta[y][i+1];
    top[x]--,top[y]--;
    del(x),del(y),ins(x),ins(y);
}
int main()
{
    int T,i,_,j,p;
    freopen("meow.in","r",stdin),freopen("meow.out","w",stdout);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%*d%d%*d",&m); // k=n*2-1;
        for(i=0;i<m;i++) scanf("%d",&a[i]),b[i]=a[i];
        sort(b,b+m),k=unique(b,b+m)-b;
        for(i=0;i<m;i++) a[i]=lower_bound(b,b+k,a[i])-b+1;
        n=(k+2)>>1;
        for(i=1;i<=n;i++) top[i]=-1;
        for(i=n+1;i<=n+4;i++) L[i]=R[i]=i;
        for(i=1;i<=k;i++) pos[i]=-1;
        for(i=1;i<=n;i++) ins(i);
        for(i=1;i<=k;i++) vis[i]=-1;
        tot=0,cnt=0;
        for(i=0;i<m;i++,assert(R[n+4]==n+4))
            if(pos[a[i]]==-1)
                if(R[n+2]!=n+2)
                    oper1(pos[a[i]]=R[n+2],a[i]);
                else if(R[R[n+1]]!=n+1)
                    oper1(pos[a[i]]=R[n+1],a[i]);
                // else if(a[i]==a[i+1])
                //     oper1(pos[a[i]]=R[n+1],a[i]);
                // else
                //     assert(i+1<m && pos[a[i+1]]!=-1),
                //     oper1(pos[a[i]]=pos[a[i+1]],a[i]);
                else
                {
                    assert(R[n+1]!=n+1),_=R[n+1];
                    for(j=i+1;j<m;j++)
                        if(a[j]==a[i] || (pos[a[j]]!=-1 && sta[pos[a[j]]][0]==a[j]))
                            break;
                        else vis[a[j]]=i;
                    assert(j<m);
                    if(a[j]==a[i])
                    {
                        oper1(_,a[i]);
                        for(p=i+1;p<j;p++) tmp[a[p]]=pos[a[p]];
                        for(p=i+1;p<j;p++) oper1(pos[a[p]],a[p]);
                        for(p=i+1;p<j;p++)
                            if(pos[a[p]]==-1) pos[a[p]]=tmp[a[p]];
                            else pos[a[p]]=-1;
                        assert(sta[_][top[_]]==a[i]),oper1(_,a[i]);
                    }
                    else if(vis[sta[pos[a[j]]][1]]!=i)
                    {
                        oper1(pos[a[i]]=pos[a[j]],a[i],1);
                        for(p=i+1;p<j;p++) oper1(pos[a[p]],a[p]);
                        for(p=i+1;p<j;p++) tmp[a[p]]=pos[a[p]];
                        for(p=i+1;p<j;p++)
                            if(pos[a[p]]==-1) pos[a[p]]=tmp[a[p]];
                            else pos[a[p]]=-1;
                        oper1(_,a[j]),oper2(pos[a[j]],_),pos[a[j]]=-1;
                    }
                    else
                    {
                        oper1(pos[a[i]]=_,a[i]);
                        for(p=i+1;p<j;p++)
                            if(oper1(pos[a[p]],a[p]),pos[a[p]]==pos[a[j]])
                                pos[a[p]]=_;
                        for(p=i+1;p<j;p++) tmp[a[p]]=pos[a[p]];
                        for(p=i+1;p<j;p++)
                            if(pos[a[p]]==-1) pos[a[p]]=tmp[a[p]];
                            else pos[a[p]]=-1;
                        assert(top[pos[a[j]]]==0),oper1(pos[a[j]],a[j]),pos[a[j]]=-1;
                    }
                    i=j;
                }
            // else if(assert(top[pos[a[i]]]>=0),sta[pos[a[i]]][0]==a[i])
            //     assert(R[n+1]!=n+1),oper1(_=R[n+1],a[i]),oper2(_,pos[a[i]]),
            //     pos[a[i]]=-1;
            // else
            //     assert(sta[pos[a[i]]][top[pos[a[i]]]]==a[i]),oper1(pos[a[i]],a[i]),
            //     pos[a[i]]=-1;
            else if(assert(top[pos[a[i]]]>=0),sta[pos[a[i]]][top[pos[a[i]]]]==a[i])
                oper1(pos[a[i]],a[i]),pos[a[i]]=-1;
            else
                assert(R[n+1]!=n+1 && sta[pos[a[i]]][0]==a[i]),
                oper1(_=R[n+1],a[i]),oper2(_,pos[a[i]]),pos[a[i]]=-1;
        assert(cnt==m && tot<=2*m);
        for(i=1;i<=n;i++) assert(top[i]==-1);
        printf("%d\n",tot);
        for(i=0;i<tot;i++)
            if(ot[i][1]==-1) printf("1 %d\n",ot[i][0]);
            else printf("2 %d %d\n",ot[i][0],ot[i][1]);
    }
    fclose(stdin),fclose(stdout);
    return 0;
}