#include<bits/stdc++.h>
using namespace std;
set<int>s[3];
struct myque{
    int id=-1;
    int l=0,r=0,sz=0;
    void print(){
        cout<<id<<" , "<<sz<<" : "<<l<<' '<<r<<endl;
    }
    void init(int i){
        l=0,r=0,sz=0,id=i;
    }
    void push(int x){
        s[sz].erase(id);
        s[sz+1].insert(id);

        if(sz==0){
            l=x;sz++;
        }
        else if(sz==1){
            r=x;sz++;
        }
        else assert(0);
    }
    void pop_back(){
        s[sz].erase(id);
        s[sz-1].insert(id);

        if(sz==1){
            l=0;sz--;
        }
        else if(sz==2){
            r=0;sz--;
        }
        else assert(0);
    }
    void pop_front(){
        s[sz].erase(id);
        s[sz-1].insert(id);

        if(sz==1){
            l=0;sz--;
        }
        else if(sz==2){
            l=r;r=0;sz--;
        }
        else assert(0);
    }
    int back(){
        if(sz==1)return l;
        else if(sz==2)return r;
        else assert(0);
    }
}q[1001];
void _main(){
    int n,m,k,cnt=0;
    scanf("%d%d%d",&n,&m,&k);
    vector<int>pos(k+1);
    s[0]=s[1]=s[2]=set<int>();
    for(int i=1;i<=n;i++){
        s[0].insert(i);
        q[i].init(i);
    }
    vector<int>oper(m+1),in(k+1),cur_i(k+1);
    vector<pair<int,int>>exoper(m+1);

    for(int i=1;i<=m;i++){
        int cur;
        scanf("%d",&cur);
        if(!in[cur]){
            in[cur]=1;
            if(!s[0].empty()){
                int id=*s[0].begin();
                pos[cur]=id;
                oper[i]=id;
                q[id].push(cur);
            }
            else if(!s[1].empty()){
                int id=*s[1].begin();
                pos[cur]=id;
                oper[i]=id;
                q[id].push(cur);
            }
            else assert(0);
        }
        else{
            in[cur]=0;
            int lst=pos[cur]; 
                //    cout<<"cur "<<cur<<" poscur "<<lst<<endl;
            if(q[lst].back()==cur){
               oper[i]=lst;
               q[lst].pop_back();
               //topremove
            }
            else {
                if(s[0].size()!=0){
                    int id=*s[0].begin();
                    oper[i]=id;
                    q[lst].pop_front();

                    oper[i]=id;
                    exoper[i]={id,lst};
                    cnt++;
                }
                else{
                    int vac=*s[1].begin();
                    int rem=q[lst].back();
                    q[lst].pop_back();
                    q[vac].push(rem);
                    pos[rem]=vac;
                    oper[cur_i[rem]]=vac;
               //     cout<<"change "<<cur_i[rem]<<' '<<vac<<endl;

                    oper[i]=lst;
                    q[lst].pop_back();
                }
            }
            
        }
        cur_i[cur]=i;
        /*
        for(int i=1;i<=n;i++){
            q[i].print();
        }
        */
    }
    printf("%d\n",cnt+m);
    for(int i=1;i<=m;i++){
        printf("1 %d\n",oper[i]);
        if(exoper[i].first!=0){
            printf("2 %d %d\n",exoper[i].first,exoper[i].second);
        }
    }
}
int main(){
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        _main();
    }
}
