#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <utility>

constexpr int N = 2000005;

int T, n, m, k;
int a[N];
int now[305][2];
std::pair<int, int> pos[605];
std::vector<std::pair<int, int>> ans;
bool vis[605];

int main() {
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> T;
    while (T--) {
        std::cin >> n >> m >> k;
        for (int i = 1; i <= m; ++i) std::cin >> a[i];
        ans.clear();
        if (k == (n - 1) << 1) {
            std::stack<int> stk;
            for (int i = 1; i < n; ++i) stk.push(i), stk.push(i);
            for (int i = 1; i <= m; ++i)
                if (!pos[a[i]].first) {
                    int x = stk.top();
                    stk.pop();
                    ans.emplace_back(x, 0);
                    pos[a[i]].first = x;
                    if (!now[x][0]) now[x][0] = a[i];
                    else now[x][1] = a[i], pos[a[i]].second = 1;
                } else {
                    if (pos[a[i]].second || !now[pos[a[i]].first][1]) {
                        ans.emplace_back(pos[a[i]].first, 0);
                        now[pos[a[i]].first][pos[a[i]].second] = 0;
                    } else {
                        ans.emplace_back(n, 0);
                        ans.emplace_back(n, pos[a[i]].first);
                        now[pos[a[i]].first][0] = now[pos[a[i]].first][1];
                        now[pos[a[i]].first][1] = 0;
                    }
                    stk.push(pos[a[i]].first);
                    pos[a[i]].first = pos[a[i]].second = 0;
                }
        } else if (n == 2) {
            int cnt = 0;
            for (int i = 1; i <= m; ++i) {
                if (!vis[a[i]]) {
                    ++cnt;
                    if (cnt == 3) {
                        int x = 0;
                        if (!now[1][0]) x = 1;
                        if (!now[2][0]) x = 2;
                        vis[a[i]] = true;
                        vis[a[i + 1]] = false;
                        if (x) {
                            if (a[i + 1] == a[i]) ans.emplace_back(x, 0), ans.emplace_back(x, 0), --cnt;
                            else if (a[i + 1] == now[3 - x][0]) ans.emplace_back(3 - x, 0), ans.emplace_back(x, 0), ans.emplace_back(1, 2), now[3 - x][0] = now[3 - x][1], now[3 - x][1] = a[i];
                            else ans.emplace_back(x, 0), ans.emplace_back(3 - x, 0), now[x][0] = a[i], now[3 - x][1] = 0;
                        } else {
                            if (a[i + 1] == a[i]) ans.emplace_back(1, 0), ans.emplace_back(1, 0), --cnt;
                            else if (a[i + 1] == now[1][0]) ans.emplace_back(2, 0), ans.emplace_back(1, 0), now[1][0] = 0, now[2][1] = a[i];
                            else ans.emplace_back(1, 0), ans.emplace_back(2, 0), now[2][0] = 0, now[1][1] = a[i];
                        }
                        ++i, --cnt;
                    } else {
                        if (!now[1][0]) ans.emplace_back(1, 0), now[1][0] = a[i];
                        else ans.emplace_back(2, 0), now[2][0] = a[i];
                        vis[a[i]] = true;
                    }
                } else {
                    if (cnt == 1) {
                        if (now[1][0]) ans.emplace_back(1, 0), now[1][0] = 0;
                        else ans.emplace_back(2, 0), now[2][0] = 0;
                    } else {
                        int x = 0;
                        if (!now[1][0]) x = 1;
                        if (!now[2][0]) x = 2;
                        if (x) {
                            if (a[i] == now[3 - x][0]) ans.emplace_back(x, 0), ans.emplace_back(1, 2), now[3 - x][0] = now[3 - x][1], now[3 - x][1] = 0;
                            else ans.emplace_back(3 - x, 0), now[3 - x][1] = 0;
                        } else if (a[i] == now[1][0]) ans.emplace_back(1, 0), now[1][0] = 0;
                        else ans.emplace_back(2, 0), now[2][0] = 0;
                    }
                    vis[a[i]] = false;
                    --cnt;
                }
            }
        }
        std::cout << ans.size() << '\n';
        for (auto [x, y] : ans) {
            if (!y) std::cout << "1 " << x << '\n';
            else std::cout << "2 " << x << ' ' << y << '\n';
        }
    }
    return 0;
}
