#include<bits/stdc++.h>
#define poly vector<int>
#define ll long long 
#define pa pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define IOS ios::sync_with_stdio(false)
#define N 605
#define M 2000005
using namespace std;
mt19937_64 rnd(time(0));
int vis[N],nxt[N];
int n,m,K;
poly all[N];
int lst[M];
int col[M];
deque<int>q[N];
int a[M],suf[M];
void BellaKira()
{
    cin>>n>>m>>K;
    for (int i=1;i<=m;i++)
        cin>>a[i];
    if (K==2*n-2)
    {
        vector<pa>ans;
        for (int i=1;i<=m;i++)
        {
            int u=(a[i]-1)%(n-1)+1;
            if (q[u].empty())
            {
                q[u].push_back(a[i]);
                ans.push_back(mp(0ll,u));
            } else
            if (q[u].front()==a[i])
            {
                q[u].pop_front();
                ans.push_back(mp(0ll,n));
                ans.push_back(mp(u,n));
            } else
            {
                if (q[u].back()==a[i]) q[u].pop_back();
                else
                    q[u].push_back(a[i]);
                ans.push_back(mp(0ll,u));
            }
        }
        cout<<ans.size()<<'\n';
        for (auto [u,v]:ans) 
            if (!u) cout<<"1 "<<v<<'\n';
            else cout<<2<<" "<<u<<" "<<v<<'\n';
    }
}
signed main()
{
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    IOS && cin.tie(0);
    int T;
    cin>>T;
    while (T--)
    {
        BellaKira();
    }
}