#include <bits/stdc++.h>

using namespace std;

namespace IO{
    template <typename T> void read(T &x){
        bool f = false;
        char c;
        x = 0;
        while (!isdigit(c = getchar())) if (c == '-') f = true;
        while (isdigit(c)) x = 10 * x + c - '0', c = getchar();
        if (f) x = -x;
    }
    template <typename T, typename... Args> void read(T &x, Args&... args){read(x); read(args...);}
} using namespace IO;

const int N = 305, M = 2e6 + 10;

int T, n, m, k;
int a[M], l[M], r[M];
int opt[M << 1], x[M << 1], y[M << 1], cnt[M << 1];
deque<int> q[N];

int main(){

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

    read(T);
    while (T--){
        read(n, m, k);
        for (int i = 1; i <= m; i++) read(a[i]);

        for (int i = 1; i <= k; i++) cnt[i] = 0;
        for (int i = 1; i <= m; i++){
            if (cnt[a[i]]) l[i] = cnt[a[i]], r[cnt[a[i]]] = i;
            cnt[a[i]] = i;
        }

        for (int i = 1; i <= n; i++) q[i].clear();

        int op = 0;
        for (int o = 1; o <= m; o++){
            for (int i = 1; i <= n; i++)
                for (int j = i + 1; j <= n; j++)
                    if (!q[i].empty() and !q[j].empty() and a[q[i].front()] == a[q[j].front()]){
                        opt[++op] = 2;
                        x[op] = i, y[op] = j;
                        q[i].pop_front(), q[j].pop_front();
                    }
            bool f = false;
            for (int j = 1; j <= n; j++){
                if (!q[j].empty() and a[q[j].back()] == a[o]){
                    opt[++op] = 1;
                    x[op] = j;
                    q[j].pop_back();
                    f = true;
                    break;
                }
            } if (f) continue;

            for (int i = 1; i <= n; i++){
                if (!q[i].empty() and r[q[i].back()] > r[o]){
                    opt[++op] = 1;
                    x[op] = i;
                    q[i].emplace_back(o);
                    f = true;
                    break;
                }
            }

            if (f) continue;

            for (int i = 1; i <= n; i++)
                if (q[i].empty()){
                    opt[++op] = 1;
                    x[op] = i;
                    q[i].emplace_back(o);
                    f = true;
                    break;
                }

            if (f) continue;

            opt[++op] = 1;
            x[op] = 1;
            q[1].emplace_back(o);

        }
        printf("%d\n", op);
        for (int i = 1; i <= op; i++){
            if (opt[i] == 1) printf("1 %d\n", x[i]);
            else printf("2 %d %d\n", x[i], y[i]);
        }
    }

    return 0;
}