#include <bits/stdc++.h>
using namespace std;

namespace IO {
inline int read() {
    int x = 0, f = 0;
    char ch = getchar();
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
    return f ? -x : x;
}
template<typename T>
inline void write(T x) {
    static int stk[65], top;
    top = 0;
    if (x < 0) putchar('-'), x = -x;
    do {
        stk[++top] = x % 10;
        x /= 10;
    } while (x);
    while (top) {
        putchar(stk[top] + '0');
        top--;
    }
}
template<typename T>
inline void write(T x, char ch) {
    write(x), putchar(ch);
}
}

const int N = 2000005;

vector<array<int, 3>> op;
int n, m, k;


namespace BRUTE {
int pos[N];
int stk[N][2];
void brute() {
    op.clear();
    for (int i = 1; i <= m; i++) {
        int x;
        scanf("%d", &x);
        if (!pos[x]) {
            for (int j = 1; j <= n; j++) {
                if (!stk[j][0]) {
                    stk[j][0] = x;
                    pos[x] = 2 * j;
                    op.push_back({1, j});
                    // printf("1 %d\n", j);
                    break;
                }
                if (!stk[j][1]) {
                    stk[j][1] = x;
                    pos[x] = 2 * j + 1;
                    op.push_back({1, j});
                    // printf("1 %d\n", j);
                    break;
                }
            }
            continue;
        }
        if (pos[x] % 2 == 1) {
            op.push_back({1, pos[x] / 2});
            // printf("1 %d\n", pos[x] / 2);
            stk[pos[x] / 2][1] = 0;
            pos[x] = 0;
        } else {
            int f = 0;
            for (int i = 1; i <= n; i++)
                if (!stk[i][0]) {
                    f = i;
                    break;
                }
            op.push_back({1, f});
            op.push_back({2, pos[x] / 2, f});
            // printf("2 %d %d\n", pos[x] / 2, f);
            if (stk[pos[x] / 2][1]) {
                int who = stk[pos[x] / 2][1];
                pos[who]--, stk[pos[x] / 2][0] = who, stk[pos[x] / 2][1] = 0; 
            } else {
                stk[pos[x] / 2][0] = 0;
            }
            pos[x] = 0;
        }
    }
    printf("%d\n", op.size());
    for (auto it: op) {
        if (it[0] == 1)
            printf("%d %d\n", it[0], it[1]);
        else
            printf("%d %d %d\n", it[0], it[1], it[2]);
    }
}
}

namespace brt {
int stk[55][55], top[55], down[55];
int a[55], flag;
void dfs(int u) {
    if (flag) {
        return;
    }
    if (u == m + 1) {
        bool ok = 1;
        for (int i = 1; i <= n; i++)
            if (down[i] != top[i]) ok = 0;
        if (ok) {
            printf("%d\n", op.size());
            for (auto it: op) {
                if (it[0] == 1)
                    printf("%d %d\n", it[0], it[1]);
                else
                    printf("%d %d %d\n", it[0], it[1], it[2]);
            }
            flag = 1;
            return;
        }
        return;
    }
    for (int i = 1; i <= n; i++) {
        if (top[i] > down[i]) {
            if (stk[i][top[i]] == a[u]) {
                op.push_back({1, i});
                top[i]--;
                dfs(u + 1);
                op.pop_back();
                stk[i][++top[i]] = a[u];
            } else {
                op.push_back({1, i});
                stk[i][++top[i]] = a[u];
                dfs(u + 1);
                op.pop_back();
                stk[i][top[i]--] = 0;
            }
        } else {
            bool ok = 0;
            for (int j = 1; j <= n; j++)
                if (i != j && stk[j][down[j]] == a[u]) {
                    ok = 1;
                    op.push_back({1, i});
                    op.push_back({2, i, j});
                    down[j]++;
                    dfs(u + 1);
                    op.pop_back();
                    op.pop_back();
                    down[j]--;
                }
            if (!ok) {
                op.push_back({1, i});
                stk[i][++top[i]] = a[u];
                dfs(u + 1);
                op.pop_back();
                stk[i][top[i]--] = 0;
            }
        }
    }
}
void brut() {
    flag = 0;
    for (int i = 1; i <= n; i++) {
        down[i] = top[i] = 0;
    }
    memset(stk, 0, sizeof(stk));
    for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
    dfs(1);
}
}

void solve() {
    scanf("%d%d%d", &n, &m, &k);
    if (k == 2 * n - 2) {
        BRUTE::brute();
        return;
    }
    brt::brut();
}

int main() {
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);
    int T = IO::read();
    while (T--) solve();
    return 0;
}