#define ssh(x)<x>
#include ssh(bits/stdc++.h)
#define rfor(x...)for(register x)
#define rep(i,l,r)rfor(ll i=l;i<=r;i++)
#define ref(i,l,r)rfor(ll i=l;i<r;i++)
#define per(i,l,r)rfor(ll i=l;i>=r;i--)
#define rev(i,u,v)rfor(ll i=head[u],v;v=to[i],i;i=next[i])
#define rej(i,s)rfor(ll i=s;i;i=(i-1)&(s))
#define re0(i,s)rfor(ll i=s;~i;i=i?(i-1)&(s)):-1)
#define red(i,n)rfor(ll i=n;i;i>>=1)
#define IO(x...)((*#x!='/'||#x[1])&&(*#x&&freopen(#x".in","r",stdin)&&freopen(#x".out","w",stdout),gc=fgc,pc=fpc,atexit(fout)))
typedef long long ll;
typedef const ll cll;
typedef unsigned long long ull;
cll N=1e6+7,mod=998244353,iv2=(mod+1)/2,iz=1<<21,oz=1<<22;
typedef ll aN[N];
char is[iz],*i1=is,*i2=is,os[oz],*o1=os,*o2=os+oz;
int fgc(){
    return i1==i2&&is==(i2=is+fread(i1=is,1,iz,stdin))?-1:*i1++;
}
void fout(){
    fwrite(os,o1-os,1,stdout),o1=os;
}
int fpc(int c){
    if(o1==o2)fout();
    return*o1++=c;
}
int(*gc)()=getchar,(*pc)(int)=putchar,wt[126];
int readchar(int l=33,int r=126){
    if(l>r)std::swap(l,r);
    int c=gc();
    for(;c<l||c>r;c=gc());
    return c;
}
ll readll(){
    ll x=0,w=1;
    int c=gc();
    for(;c<48||c>57;c=gc())c-45||(w=-w);
    for(;c>47&&c<58;c=gc())x=x*10+c-48;
    return x*w;
}
void writell(cll u,int c=32){
    int t=0;
    rfor(ull n=u<0?pc(45),0ull-u:u;n;n/=10)wt[++t]=n%10^48;
    for(t||pc(48);t;)pc(wt[t--]);
    c&&pc(c);
}
int mygets(char*s,int c=0){
    char*t=s+1;
    while((*s=gc())<33);
    while((*t=gc())>32)t++;
    c&&(*t++=c),*t=0;
    return t-s;
}
int myputs(const char*s,int c=10){
    const char*t=s;
    while(*t)pc(*t++);
    c&&pc(c);
    return t-s+(c!=0);
}
cll IO_res=IO(meow),T=readll();
void init(){
}
aN a,w,q,d,u;
aN op,x,y,nxt;
void calc(){
    cll n=readll(),m=readll(),k=readll();
    rep(i,1,m)a[i]=readll();
    ll tans=0;
    if(k==2*n-2){
        rep(i,1,m){
            cll x=a[i];
            ll flag=0;
            rep(i,1,n){
                if(d[i]==x){
                    ++tans,op[tans]=1,::x[tans]=n;
                    ++tans,op[tans]=2,::x[tans]=n,y[tans]=i;
                    d[i]=u[i],u[i]=0;
                        flag=1;
                    break;
                }
                if(u[i]==x){
                    ++tans,op[tans]=1,::x[tans]=i;
                    u[i]=0;
                        flag=1;
                    break;
                }
            }
            if(!flag){
                rep(i,1,n){
                    if(!d[i]){
                    ++tans,op[tans]=1,::x[tans]=i;
                        d[i]=x;
                        break;
                    }
                    if(!u[i]){
                    ++tans,op[tans]=1,::x[tans]=i;
                        u[i]=x;
                        break;
                    }
                }
            }
        }
        /*ll t=0,h=1;
        rep(i,1,2*n)q[++t]=i;
        rep(i,1,n){
            cll x=a[i];
            if(w[x]){
                if(w[x]<=n-1)writell(1),writell(n,10),writell(2),writell(w[x]),writell(n,10);
                else writell(1),writell(w[x]-(n-1),10);
                q[++t]=w[x],w[x]=0;
            }else{
                w[x]=q[h++];
                if(w[x]<=n-1)writell(1),writell(n,10),writell(2),writell(w[x]),writell(n,10);
                else writell(1),writell(w[x]-(n-1),10);
            }
        }*/
    }else{
        static aN lst;
        per(i,m,1)if(!lst[a[i]])lst[a[i]]=i;
        else nxt[i]=lst[a[i]],lst[a[i]]=0;
        if(n==2){
            
            /*cll a=
            rep(i,1,m){
                cll x=a[i];
                
            }*/
            ll d=0,u=0,z=0,w=1;
            rep(i,1,m){
                cll x=a[i];
                if(!z){
                    if(!d){
                        ++tans,op[tans]=1,::x[tans]=w,d=x;
                        continue;
                    }
                    if(!u){
                        ++tans,op[tans]=1,::x[tans]=w,u=x;
                        continue;
                    }
                    if(z==x){
                        ++tans,op[tans]=1,::x[tans]=3-w,u=0;
                        continue;
                    }
                    if(x==u){
                        ++tans,op[tans]=1,::x[tans]=w,u=0;
                        continue;
                    }
                    if(x==d){
                        ++tans,op[tans]=1,::x[tans]=3-w;
                        ++tans,op[tans]=2,::x[tans]=1,y[tans]=2;
                        d=u,u=0;
                        continue;
                    }
                    if(a[i+1]==x){
                        i++;
                        ++tans,op[tans]=1,::x[tans]=3-w;
                        ++tans,op[tans]=1,::x[tans]=3-w;
                        continue;
                    }
                    if(a[i+1]==d){
                        i++;
                        ++tans,op[tans]=1,::x[tans]=w;
                        ++tans,op[tans]=1,::x[tans]=3-w;
                        ++tans,op[tans]=2,::x[tans]=1,y[tans]=2;
                        d=u,u=x;
                        continue;
                    }
                    if(a[i+1]==u){
                        i++;
                        ++tans,op[tans]=1,::x[tans]=3-w;
                        ++tans,op[tans]=1,::x[tans]=w;
                        u=0,z=x;
                        continue;
                    }
                }else{
                    assert(!u);
                    if(d==x){
                        ++tans,op[tans]=1,::x[tans]=w,d=0;
                        continue;
                    }
                    if(z==x){
                        ++tans,op[tans]=1,::x[tans]=3-w,z=0;
                        continue;
                    }
                    if(a[i+1]==x){
                        i++;
                        ++tans,op[tans]=1,::x[tans]=3-w;
                        ++tans,op[tans]=1,::x[tans]=3-w;
                        continue;
                    }
                    if(a[i+1]==d){
                        w=3-w;
                        std::swap(d,z);
                    }
                    if(a[i+1]==z){
                        i++;
                        ++tans,op[tans]=1,::x[tans]=w,u=x;
                        ++tans,op[tans]=1,::x[tans]=3-w,z=0;
                        continue;
                    }
                }
            }
        }
    }
    writell(tans,10);
    rep(i,1,tans)writell(op[i]),writell(x[i],op[i]==1?10:32),op[i]==2&&(writell(y[i],10),0);
}
int main(){
    init();
    rep(i,1,T)calc();
    return 0;
}
/*
3
2 10 3
1 2 3 2 3 3 2 1 3 2
2 8 3
1 2 3 2 2 3 1 2
2 8 3
1 2 3 2 2 1 3 2
*/
