#include<bits/stdc++.h>
#define rd(x) x=read()
using namespace std;
const int mod=998244353;
const int N=2e6+5;
const int M=605;
int read()
{
    int x=0,f=1;char c=getchar();
    while (c>'9' || c<'0') {if (c=='-') f=-1;c=getchar();}
    while ('0'<=c && c<='9') {x=x*10+c-'0';c=getchar();}
    return x*f;
}
int Q;
int n,m,k;
int a[N],A[N],la[N];
int id[N];
int tot[N];
bool flag[N];
vector<int> s[N];
int h[N];
struct Node{int op,x,y;};
vector<Node> ans;
void op1(int st,int x)
{
    //printf("op1(%d,%d)\n",st,x);
    if (s[st].size()==h[st]) s[st].push_back(x);else
    if (s[st][s[st].size()-1]==x) s[st].pop_back();
    else s[st].push_back(x);
    ans.push_back((Node){1,st,0});
}
void op2(int st1,int st2)
{
    if (s[st1][h[st1]]=s[st2][h[st2]]) {h[st1]++,h[st2]++;ans.push_back((Node){2,st1,st2});}
    //printf("op2(%d,%d)\n",st1,st2);
}
int CNT[M];
bool cmp(int x,int y){return CNT[x]>CNT[y];}
void solve()
{
    rd(n);rd(m);rd(k);
    for (int i=1;i<=m;i++) rd(A[i]);
    bool OK=0;
    for (int i=1;i<=k;i++) id[i]=i;
    for (int i=1;i<=k;i++) CNT[i]=0;
    for (int i=1;i<=m;i++) CNT[A[i]]++;
    sort(id+1,id+k+1,cmp);
    while (OK==0)
    {
        for (int i=1;i<=n;i++) s[i].clear(),h[i]=0;ans.clear();
        
        for (int i=1;i<=m;i++) a[i]=id[A[i]];
        int cnt=0,lap=0;
        for (int i=1;i<=m;i++)
        {

            if (a[i]==k && k%2==1)
            {
                cnt++;
                if (cnt%2==1)
                {
                    int pos=0;
                    for (int j=i+1;j<=m;j++)
                    {
                        if (a[j]==k) break;
                        tot[(a[j]+1)/2]++;
                    }
                    lap=1;
                    for (int i=1;i<=n-1;i++)
                    {
                        if (tot[i]==0 || (tot[i]==1 && s[i].size()-h[i]<=1)) {lap=i;break;}
                    }
                    for (int j=i+1;j<=m;j++)
                    {
                        if (a[j]==k) break;
                        tot[(a[j]+1)/2]--;
                    }
                    lap=rand()%(n)+1;
                    op1(lap,a[i]);
                } else op1(lap,a[i]);
            } else 
            {
                int g=(a[i]+1)/2;
                if (s[g].size()==h[i]) op1(g,a[i]);else 
                if (s[g][s[g].size()-1]==a[i]) op1(g,a[i]);else
                if (s[g][h[g]]==a[i]) op1(n,a[i]),op2(g,n);else 
                op1(g,a[i]);
            }/*
            for (int i=1;i<=n;i++)
            {
                for (int j=h[i];j<s[i].size();j++) cout<<s[i][j];
                cout<<"\n";
            }*/
        }
        OK=1;
        for (int i=1;i<=n;i++) if (h[i]!=s[i].size()) OK=0;
        if (OK==0)
        {
            for (int i=1;i<=k;i++) id[i]=i;
            random_shuffle(id+1,id+k+1);
        }
    }
    cout<<ans.size()<<"\n";
    for (Node i:ans)
    {
        if (i.op==1) printf("1 %d\n",i.x);else 
        printf("2 %d %d\n",i.x,i.y);
    }
}
signed main()
{
    srand(time(NULL));
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    
    rd(Q);
    while (Q--) solve();
    fclose(stdin);
    fclose(stdout);
    return 0;
}
//