#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;

constexpr int N = 2e6 + 5;
int n, m, k;
int a[N], st[N][4], pos[N], lev[N];
bool vis[N];
struct ddd { int a, b, c; };
std::vector<ddd> ans;

signed main() {
    freopen("meow.in", "r", stdin), freopen("meow.out", "w", stdout);
    std::ios::sync_with_stdio(false), cin.tie(nullptr);

    int _;
    cin >> _;
    while (_--) {
        ans.clear();
        cin >> n >> m >> k;
        // memset(a, 0, sizeof a);
        // memset(pos, 0, sizeof pos);
        // memset(lev, 0, sizeof lev);
        // memset(vis, 0, sizeof vis);
        // memset(st, 0, sizeof st);
        for (int i = 1; i <= m; ++i) {
            a[i] = pos[i] = lev[i] = 0;
            vis[i] = 0;
            for (int j = 0; j < 4; ++j) st[i][j] = 0;
        }
        bool flag = true;
        for (int i = 1; i <= m; ++i) {
            cin >> a[i];
            if (vis[a[i]] && i <= m / 2) flag = false;
            vis[a[i]] = true;
        }
        if (flag) {
            for (int i = 1; i <= m / 2; ++i) pos[a[i]] = i;
            int t1 = pos[a[m / 2 + 1]], t2 = pos[a[m / 2 + 2]];
            for (int i = m / 2 + 1; i <= m; ++i) {
                for (int j = i + 1; j <= m; ++j) {
                    if (t1 < t2) break;
                    t1 = pos[a[i]], t2 = pos[a[j]];
                }
                if (t1 < t2) break;
            }
            for (int i = 1; i <= m; ++i) pos[i] = 0;
            int cnt = 2;
            for (int i = 1; i <= m / 2 - 1; ++i) {
                if (st[cnt][1] != 0 && st[cnt][2] != 0) ++cnt;
                if (i == t1 || i == t2) {
                    ans.push_back({1, 1, 0});
                    if (st[1][1] == 0) {
                        pos[a[i]] = 1, lev[a[i]] = 1, st[1][1] = a[i];
                    } else {
                        pos[a[i]] = 1, lev[a[i]] = 2, st[1][2] = a[i];
                    }
                } else
                if (st[cnt][1] == 0) {
                    pos[a[i]] = cnt, lev[a[i]] = 1, st[cnt][1] = a[i];
                    ans.push_back({1, cnt, 0});
                } else {
                    pos[a[i]] = cnt, lev[a[i]] = 2, st[cnt][2] = a[i];
                    ans.push_back({1, cnt, 0});
                }
            }
            ans.push_back({1, 1, 0});
            for (int i = m / 2 + 1; i <= m; ++i) {
                if (a[i] == a[m / 2]) {
                    ans.push_back({1, 1, 0});
                    continue;
                }
                if (lev[a[i]] == 2) {
                    st[pos[a[i]]][2] = 0;
                    ans.push_back({1, pos[a[i]], 0});
                    pos[a[i]] = lev[a[i]] = 0;
                } else {
                    st[pos[a[i]]][1] = st[pos[a[i]]][2];
                    st[pos[a[i]]][2] = 0;
                    lev[st[pos[a[i]]][1]] = 1;
                    ans.push_back({1, n, 0});
                    ans.push_back({2, pos[a[i]], n});
                    pos[a[i]] = lev[a[i]] = 0;
                }
            }
        } else
        for (int i = 1; i <= m; ++i) {
            if (pos[a[i]]) {
                if (lev[a[i]] == 2) {
                    st[pos[a[i]]][2] = 0;
                    ans.push_back({1, pos[a[i]], 0});
                    pos[a[i]] = lev[a[i]] = 0;
                } else {
                    st[pos[a[i]]][1] = st[pos[a[i]]][2];
                    st[pos[a[i]]][2] = 0;
                    lev[st[pos[a[i]]][1]] = 1;
                    ans.push_back({1, n, 0});
                    ans.push_back({2, pos[a[i]], n});
                    pos[a[i]] = lev[a[i]] = 0;
                }
            } else {
                for (int j = 1; j < n; ++j)
                    if (st[j][2] == 0) {
                        if (st[j][1] == 0) {
                            pos[a[i]] = j, lev[a[i]] = 1, st[j][1] = a[i];
                            ans.push_back({1, j, 0});
                        } else {
                            pos[a[i]] = j, lev[a[i]] = 2, st[j][2] = a[i];
                            ans.push_back({1, j, 0});
                        }
                        break;
                    }
            }
        }
        cout << ans.size() << '\n';
        for (auto e : ans) {
            if (e.a == 1) cout << e.a << ' ' << e.b << '\n';
            else cout << e.a << ' ' << e.b << ' ' << e.c << '\n';
        }
    }


    return 0;
}
