#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T;
ll n, m, k;
ll a[2000005];
ll p[605];
ll st[305][2];
ll cnt = 0;
void work() {
    cnt = 0;
    scanf("%lld%lld%lld",&n,&m,&k);
    for ( ll i = 1 ; i <= m ; ++i ) {
        scanf("%lld",a+i);
    }
    for ( ll i = 1 ; i <= k ; ++i ) {
        p[i] = 0;
    }
    for ( ll i = 1 ; i <= n ; ++i ) {
        st[i][0] = st[i][1] = 0;
    }
    vector< pair<ll,pair<ll,ll> > >ans;
    if ( k == 2 * n - 2 ) {
        for ( ll i = 1; i <= m; ++i ) {
            if ( !p[a[i]] ) {
                p[a[i]] = ( ++cnt + 1 ) / 2;
            }
            if ( st[p[a[i]]][0] == 0 ) {
                st[p[a[i]]][0] = a[i];
                ans.push_back(make_pair(1ll,make_pair(p[a[i]],0)));
            } else if ( st[p[a[i]]][0] == a[i] ) {
                ans.push_back(make_pair(1ll,make_pair(n,0)));
                ans.push_back(make_pair(2ll,make_pair(p[a[i]],n)));
                st[p[a[i]]][0] = st[p[a[i]]][1];
                st[p[a[i]]][1] = 0;
            } else if ( st[p[a[i]]][1] == 0 ) {
                st[p[a[i]]][1] = a[i];
                ans.push_back(make_pair(1ll,make_pair(p[a[i]],0)));
            } else {
                ans.push_back(make_pair(1ll,make_pair(p[a[i]],0)));
                st[p[a[i]]][1] = 0;
            }
        }
        printf("%ld\n",ans.size());
        for ( auto x : ans ) {
            printf("%lld ",x.first);
            if ( x.first == 1 ) {
                printf("%lld\n",x.second.first);
            } else {
                printf("%lld %lld\n",x.second.first,x.second.second);
            }
        }
    }
}
int main() {
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    scanf("%lld",&T);
    while (T--) work();
}