#include<bits/stdc++.h>
using namespace std;
int read()
{
    int x=0;bool f=0;char c=getchar();
    for(;!isdigit(c);c=getchar())f^=!(c-45);
    for(;isdigit(c);c=getchar())x=x*10+c-48;
    if(f)x=-x;return x;
}
int ti;
int n,m,k;
int a[2000006];
int kk[605],v[605][2];
set<pair<int,int> >st;
struct abc
{
    int k,x,y;
};
vector<abc>ans;
signed main()
{
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    ti=read();
    while(ti--)
    {
        st.clear();ans.clear();
        int n=read(),m=read(),k=read(),ed=n;
        for(int i=1;i<=m;i++)a[i]=read();
        for(int i=1;i<n;i++)st.insert({i,0}),st.insert({i,1});
        if(k==2*n-1)
        {
            for(int i=1;i<=m;i++)
            {
                if(kk[a[i]])
                {
                    int ss,tt;
                    if(kk[a[i]]>n)
                    {
                        ss=kk[a[i]]-n;
                        tt=1;
                    }
                    else
                    {
                        ss=kk[a[i]];
                        tt=0;
                    }
                    kk[a[i]]=0;
                    if(tt||st.find({ss,1})!=st.end())
                    {
                        //cout<<"1 "<<ss<<"\n";
                        ans.push_back({1,ss});
                        st.insert({ss,tt});
                        v[ss][tt]=0;
                    }
                    else
                    {
                        ans.push_back({1,ed});
                        ans.push_back({2,ss,ed});
                        //cout<<"1 "<<ed<<"\n";
                        //cout<<"2 "<<ss<<" "<<ed<<"\n";
                        st.insert({ss,1});
                        kk[v[ss][1]]-=n;
                        v[ss][0]=v[ss][1];
                        v[ss][1]=0;
                    }
                }
                else if(st.size()) 
                {
                    auto t=st.begin();
                    ans.push_back({1,t->first});
                    //cout<<1<<" "<<t->first<<"\n";
                    kk[a[i]]=t->first+(n*t->second);
                    v[t->first][t->second]=a[i];
                    st.erase(t);
                }
                else
                {
                    int r=n;
                    for(int j=i+1;j<=m;j++)
                    {
                        if(kk[a[j]]<=n)
                        {
                            r=j;break;
                        }
                    }
                    int tp=0;
                    for(int j=i+1;j<r;j++)
                    {
                        if(kk[a[j]]==kk[a[r]]+n)
                        {
                            tp=j;
                            break;
                        }
                    }
                    if(tp)
                    {
                        ans.push_back({1,ed});
                        //cout<<1<<" "<<ed<<"\n";
                        kk[a[i]]=ed;
                        v[ed][0]=a[i];
                        st.insert({ed,1});
                        ed=kk[a[r]];
                        for(int j=i+1;j<=r;j++)
                        {
                            int ss,tt;
                            if(kk[a[j]]>n)
                            {
                                ss=kk[a[j]]-n;
                                tt=1;
                            }
                            else
                            {
                                ss=kk[a[j]];
                                tt=0;
                            }
                            kk[a[j]]=0;
                            if(tt||st.find({ss,1})!=st.end())
                            {
                                ans.push_back({1,ss});
                                //cout<<"1 "<<ss<<"\n";
                                st.insert({ss,tt});
                            }
                            else
                            {
                                ans.push_back({1,ed});
                                ans.push_back({2,ss,ed});
                                //cout<<"1 "<<ed<<"\n";
                                //cout<<"2 "<<ss<<" "<<ed<<"\n";
                                st.insert({ss,1});
                                kk[v[ss][1]]-=n;
                                v[ss][0]=v[ss][1];
                                v[ss][1]=0;
                            }
                        }
                        st.erase(st.find({ed,0}));
                        st.erase(st.find({ed,1}));
                    }
                    else
                    {
                        ans.push_back({1,kk[a[r]]});
                        //cout<<1<<' '<<kk[a[r]]<<'\n';
                        int aa=kk[a[r]];
                        for(int j=i+1;j<=r;j++)
                        {
                            int ss,tt;
                            if(kk[a[j]]>n)
                            {
                                ss=kk[a[j]]-n;
                                tt=1;
                            }
                            else
                            {
                                ss=kk[a[j]];
                                tt=0;
                            }
                            kk[a[j]]=0;
                            if(tt||st.find({ss,1})!=st.end())
                            {
                                ans.push_back({1,ss});
                                //cout<<"1 "<<ss<<"\n";
                                st.insert({ss,tt});
                            }
                            else
                            {
                                ans.push_back({1,ed});
                                ans.push_back({2,ss,ed});
                                //cout<<"1 "<<ed<<"\n";
                                //cout<<"2 "<<ss<<" "<<ed<<"\n";
                                st.insert({ss,1});
                                kk[v[ss][1]]-=n;
                                v[ss][0]=v[ss][1];
                                v[ss][1]=0;
                            }
                        }
                        st.erase({aa,1});
                        kk[a[i]]=aa+n;
                        v[aa][1]=a[i];
                    }
                    i=r;
                }
            }
        }
        else
        {
            for(int i=1;i<=m;i++)
            {
                if(kk[a[i]])
                {
                    int ss,tt;
                    if(kk[a[i]]>n)
                    {
                        ss=kk[a[i]]-n;
                        tt=1;
                    }
                    else
                    {
                        ss=kk[a[i]];
                        tt=0;
                    }
                    kk[a[i]]=0;
                    if(tt||st.find({ss,1})!=st.end())
                    {
                        ans.push_back({1,ss});
                       // cout<<"1 "<<ss<<"\n";
                        st.insert({ss,tt});
                    }
                    else
                    {
                        ans.push_back({1,n});
                        ans.push_back({2,ss,n});
                        //cout<<"1 "<<n<<"\n";
                        //cout<<"2 "<<ss<<" "<<n<<"\n";
                        st.insert({ss,1});
                        kk[v[ss][1]]-=n;
                        v[ss][0]=v[ss][1];
                        v[ss][1]=0;
                    }
                }
                else 
                {
                    auto t=st.begin();
                    ans.push_back({1,t->first});
                    //cout<<1<<" "<<t->first<<"\n";
                    kk[a[i]]=t->first+(n*t->second);
                    v[t->first][t->second]=a[i];
                    st.erase(t);
                }
            }
        }
        cout<<ans.size()<<"\n";
        for(auto t:ans)
        {
            if(t.k==1)cout<<1<<" "<<t.x<<"\n";
            else cout<<2<<" "<<t.x<<' '<<t.y<<"\n";
        }
    }
}