#include<bits/stdc++.h>
using namespace std;
#define fo(v, a, b) for(int v = a; v <= b; v++)
#define fr(v, a, b) for(int v = a; v >= b; v--)
#define cl(a, v) memset(a, v, sizeof(a))

const int N = 310, K = 610, M = 2e6 + 10;

int n, m, k, a[M];
vector<pair<int, int> > ans;

namespace K2 {
    int v1[N], v2[N], pre[K], pos[K];
    int q[2 * M], l, r;
    void Solve() {
        cl(pre, 0), cl(pos, 0), cl(v1, 0), cl(v2, 0);
        l = 1, r = n; fo(i,1,n-1) q[i] = i;
        fo(i,1,m) {
            if(pre[a[i]]) {
                int p = pos[a[i]];
                if(v1[p] == a[i]) {
                    ans.push_back(make_pair(n, -1)),
                    ans.push_back(make_pair(p, n));
                    v1[p] = v2[p], v2[p] = 0;
                } else {
                    ans.push_back(make_pair(p, -1));
                    v2[p] = 0;
                }
                if(v1[i]) q[++r] = pos[a[i]];
            } else {
                ans.push_back(make_pair(q[l], -1));
                pos[a[i]] = q[l], pre[a[i]] = i;
                if(v1[q[l]] == 0) v1[q[l]] = a[i];
                else v2[q[l]] = a[i], l++;
            }
        }
    }
}

int v[K], nxt[M], pos[K], cur;
deque<int> q[N];

void print() {
    printf("%d\n", (int)ans.size());
    for(auto t : ans) {
        if(t.second == -1) printf("1 %d\n", t.first);
        else printf("2 %d %d\n", t.first, t.second);
    }
    // fo(i,1,n) q[i].clear();
    // int cur = 0;
    // for(auto t : ans) {
    //     if(t.second == -1) {
    //         cur++;
    //         if(q[t.first].size() && a[cur] == q[t.first].back())
    //             q[t.first].pop_back();
    //         else q[t.first].push_back(a[cur]);
    //     } else {
    //         assert(q[t.first].front() == q[t.second].front());
    //         q[t.first].pop_front(), q[t.second].pop_front();
    //     }
    // }
    // fo(i,1,n) assert(q[i].empty());
}

void Main() {
    scanf("%d%d%d", &n, &m, &k);
    fo(i,1,m) scanf("%d", &a[i]), nxt[i] = 0;
    ans.clear(); fo(i,1,n) q[i].clear();

    if(k == 2 * n - 2)
        return K2 :: Solve(), print();

    cl(v, 0), cl(pos, 0), cur = 0;
    fr(i,m,1) {
        if(v[a[i]]) nxt[i] = v[a[i]], v[a[i]] = 0;
        else v[a[i]] = i;
    }
    bool f = false;
    fo(i,1,m) {
        if(nxt[i]) cur++; else cur--;
        if(f) {
            if(nxt[i]) {
                int z = -1;
                fo(j,1,n) if((int)q[j].size() == 1
                    && (z == -1 || q[j].back() < q[z].back()))
                    z = j;
                ans.push_back(make_pair(z, -1));
                q[z].push_back(nxt[i]), pos[a[i]] = z;
            } else {
                fo(j,1,n) if(q[j].back() == i) {
                    ans.push_back(make_pair(j, -1)), pos[a[i]] = 0;
                    q[j].pop_back(); if(q[j].empty()) f = false;
                    break;
                } // assert(pos[a[i]] == 0);
            }
        } else {
            int p = -1;
            fo(j,1,n) if((int)q[j].size() == 0)
                p = j;
            assert(p != -1);
            if(nxt[i]) {
                if(cur == 2 * n - 1) {
                    bool g = false;
                    fo(j,1,n) if(j != p && q[j][0] <= q[j][1]) {
                        q[j].push_back(nxt[i]), pos[a[i]] = j, g = true;
                        ans.push_back(make_pair(j, -1)); break;
                    }
                    if(!g) {
                        ans.push_back(make_pair(p, -1));
                        q[p].push_back(nxt[i]), pos[a[i]] = p, f = true;
                    }
                } else {
                    fo(j,1,n) if(j != p && (int)q[j].size() < 2) {
                        q[j].push_back(nxt[i]), pos[a[i]] = j;
                        ans.push_back(make_pair(j, -1)); break;
                    }
                }
            } else {
                int z = pos[a[i]]; pos[a[i]] = 0;
                if(q[z].back() == i)
                    ans.push_back(make_pair(z, -1)),
                    q[z].pop_back();
                else {
                    // assert(q[z].front() == i);
                    ans.push_back(make_pair(p, -1));
                    ans.push_back(make_pair(z, p));
                    q[z].pop_front();
                }
            }
        }
    }
    print();
}

int main()
{
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);

    int T; scanf("%d", &T);
    while(T--) Main();

    return 0;
}