#include <bits/stdc++.h>

template<class T, class...Cond>
using require_ = std::enable_if_t<std::__and_<T, Cond...>::value, bool>;

template<class T, require_<std::is_signed<T>> = true>
void read(T & x) {
    x = 0;
    bool f = false;
    char c = getchar();
    while (!isdigit(c)) f |= (c == '-'), c = getchar();
    while (isdigit(c)) x = (x * 10) - (c ^ 48), c = getchar();
    x = (f ? x : -x);
}

template<class T, require_<std::is_unsigned<T>> = true>
void read(T & x) {
    x = 0;
    char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
}

template<class T, class...Args>
void read(T & x, Args&...args) {
    read(x);
    read(args...);
}

constexpr int N = 305;
constexpr int M = 2e6 + 10;
constexpr int K = N * 2;

int T = 1;
int n, m, k;

int a[M], b[M];

// std::vector<int> pos[K];

void solve() {
    read(n, m, k);
    for (int i = 1; i <= m; ++ i) {
        read(a[i]);
        // pos[a[i]].emplace_back(i);
    }

    // if (n == 2) {
    //     for (int i = 1; i <= m; ++ i) {
    //         ;
    //     }
    // } else
    // if (n == 3) {
        std::deque<int> q[4];
        std::vector<std::array<int, 3>> steps;
        bool ans = false;
        auto dfs = [&](auto && dfs, int x) -> void {
            if (ans) {
                return;
            }
            if (x > m) {
                bool flg = true;
                for (int i = 1; i <= n; ++ i) {
                    if (!q[i].empty()) {
                        flg = false;
                        break;
                    }
                }
                if (flg) {
                    ans = true;
                    printf("%d\n", (int)(steps.size()));
                    for (const auto & it : steps) {
                        if (it[0] == 1) {
                            printf("1 %d\n", it[1]);
                        } else {
                            printf("2 %d %d\n", it[1], it[2]);
                        }
                    }
                }
                return;
            }
            for (int i = 1; i <= n; ++ i) {
                if (!q[i].empty() && q[i].back() == a[x]) {
                    q[i].pop_back();
                    steps.push_back({1, i});
                    dfs(dfs, x + 1);
                    steps.pop_back();
                    q[i].emplace_back(a[x]);
                } else if (q[i].empty()) {
                    bool flg = false;
                    for (int j = 1; j <= n; ++ j) {
                        if (i != j) {
                            if (!q[j].empty() && q[j].front() == a[x]) {
                                q[j].pop_front();
                                flg = true;
                                steps.push_back({1, i});
                                steps.push_back({2, i, j});
                                dfs(dfs, x + 1);
                                steps.pop_back();
                                steps.pop_back();
                                q[j].emplace_front(a[x]);
                            }
                        }
                    }
                    if (!flg) {
                        q[i].emplace_back(a[x]);
                        steps.push_back({1, i});
                        dfs(dfs, x + 1);
                        steps.pop_back();
                        q[i].pop_back();
                    }
                } else {
                    steps.push_back({1, i});
                    q[i].emplace_back(a[x]);
                    dfs(dfs, x + 1);
                    steps.pop_back();
                    q[i].pop_back();
                }
            }
        };

        dfs(dfs, 1);
    // }

    // for (int i = 1; i <= k; ++ i) {
    //     pos[i].clear();
    // }
}

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

    read(T);
    for (int t = 1; t <= T; ++ t) {
        solve();
    }
    return 0;
}
/*
(1
2 4 2
1 2 1 2
)
*/
/*
1
3 10 5
1 2 3 4 5 2 3 4 5 1
*/