#include <bits/stdc++.h>

const int M = 40;
const int N = 305;
const int C = 1005;

int T, n, m, k;
int a[C];
int Num[N], Sta[N][C], Sl[N][M], Sr[N][M], Oper[C][3], Ou[C];

inline bool Dfs(int c) {
    if (c > m) {
        for (int i = 1; i <= n; ++i) {
            if (Sl[i][c] <= Sr[i][c]) return false;
        }
        std::cout << Ou[c] << '\n';
        for (int i = 1; i <= Ou[c]; ++i) {
            std::cout << Oper[i][0] << ' ' << Oper[i][1];
            if (Oper[i][0] == 2)
             std::cout << ' ' << Oper[i][2];
            std::cout << '\n';
        }
        return true;
    }
    int d = c + 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) Sl[j][d] = Sl[j][c], Sr[j][d] = Sr[j][c];
        Ou[d] = Ou[c] + 1;
        Oper[Ou[d]][0] = 1, Oper[Ou[d]][1] = i, Oper[Ou[d]][2] = a[c];
        if (Sl[i][d] <= Sr[i][d] && Sta[i][Sr[i][d]] == a[c]) {
            --Sr[i][d];
        } else {
            Sta[i][++Sr[i][d]] = a[c];
            // if (Sr[i][d] > Sl[i][d] + 1) continue;
            // int Flag = 0;
            // for (int j = Sl[i][d]; j < Sr[i][d]; ++j) {
            //     if (Sta[i][j] == a[c]) Flag = 1;
            // }
            // if (Flag) continue;
        }
        while (true) {
            for (int j = 1; j <= k; ++j) Num[j] = 0;
            int x = -1, y = -1;
            for (int j = 1; j <= n; ++j) {
                if (Sl[j][d] > Sr[j][d]) continue;
                int &u = Num[Sta[j][Sl[j][d]]];
                if (!u) {
                    u = j;
                } else {
                    x = u, y = j;
                }
            }
            if (x == -1) break;
            ++Sl[x][d], ++Sl[y][d], ++Ou[d];
            Oper[Ou[d]][0] = 2, Oper[Ou[d]][1] = x, Oper[Ou[d]][2] = y;
        }
        if (Dfs(d)) return true;
    }
    return false;
}

int main() {
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::cin >> T;
    while (T--) {
        std::cin >> n >> m >> k;
        for (int i = 1; i <= m; ++i) std::cin >> a[i];
        for (int i = 1; i <= n; ++i) Sl[i][1] = 1, Sr[i][1] = 0;
        if (!Dfs(1)) std::cout << "ERROR" << '\n';
    }
    return 0;
}