#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int M=2e6+5,N=305;
int T,n,m,k,a[M],cnt,sz[N],ans;
int visi[N][N<<1],sol[N*10],len;
vector<int> s[N];
int main()
{
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T--)
    { 
        cin>>n>>m>>k;
        cnt=ans=len=0;
        memset(sol,0,sizeof(sol));
        memset(visi,0,sizeof(visi));
        for(int i=1;i<=n;i++) s[i].clear();
        for(int i=1;i<=m;i++) cin>>a[i];
        for(int i=1;i<=m;i++)
        {
            bool fl=0;
            for(int j=1;j<=n;j++)
            {
                if(s[j].empty()) continue;
                //cerr<<"qwq"<<s[j].front()<<" "<<s[j].back()<<endl;
                if(s[j].back()==a[i])
                {
                    ans++;
                    sol[++len]=1,sol[++len]=j;
                    visi[j][s[j].back()]--;
                    s[j].pop_back();
                    fl=1;
                    break;
                } 
                else if(s[j].front()==a[i]&&cnt<n)
                {
                    ans+=2;
                    sol[++len]=1,sol[++len]=j,sol[++len]=2,sol[++len]=j,sol[++len]=n;
                    visi[j][s[j].front()]--;
                    s[j].erase(s[j].begin());
                    fl=1;
                    break;
                }
                if(s[j].empty()) cnt--;
            }
            if(fl) continue;
            for(int j=1;j<=n;j++)
            {
                if(s[j].empty())
                {
                    ans++;
                    sol[++len]=1,sol[++len]=j;
                    visi[j][a[i]]++;
                    cnt++;
                    s[j].push_back(a[i]);
                    break;
                }
                else if(!visi[j][a[i]])
                {
                    ans++;
                    visi[j][a[i]]++;
                    sol[++len]=1,sol[++len]=j;
                    s[j].push_back(a[i]);
                    break;
                }
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(s[i].empty()) continue;
            for(int j=1;j<=n;j++)
            {
                if(s[j].empty()||i==j) continue;
                while(s[i].front()==s[j].front()&&!s[i].empty()&&!s[j].empty())
                {
                    ans++;
                    sol[++len]=2,sol[++len]=i,sol[++len]=j;
                    s[i].erase(s[i].begin());
                    s[j].erase(s[j].begin());
                }
            }
        }
        cout<<ans<<'\n';
        int qwq=0;
        for(int i=1;i<=len;i++)
        {
            if(!qwq)
            {
                if(sol[i]==1)
                {
                    cout<<1<<" ";
                    qwq=1;
                }
                else
                {
                    cout<<2<<" ";
                    qwq=2;
                }
            }
            else
            {
                cout<<sol[i]<<" ";
                qwq--;
                if(!qwq) cout<<'\n';
            }
        }
    }
    cout.flush();
    return 0;
}