#include <bits/stdc++.h>
using namespace std;
int n, m;
int pos[610];
struct node {
    int type, s1, s2;
};
vector <node> ans;
vector <int> sta[610];
vector <int> nfull;
void rmain() {
    scanf("%d%d%*d", &n, &m);
    ans.clear();
    nfull.clear();
    for (int i = 1; i < n; i++) nfull.push_back(i);
    int ppos = n;
    for (int i = 1; i <= m; i++) {
        int x;
        scanf("%d", &x);
        if (pos[x]) {
            if (sta[pos[x]].back() == x) {
                ans.push_back({1, pos[x]});
                sta[pos[x]].pop_back();
            }
            else {
                ans.push_back({1, ppos});
                ans.push_back({2, pos[x], ppos});
                sta[pos[x]].erase(sta[pos[x]].begin());
            }
            if (sta[pos[x]].size() == 1) nfull.push_back(pos[x]);
            pos[x] = 0;
            continue;
        }
        while (nfull.size() && (nfull.back() == ppos || sta[nfull.back()].size() == 2)) nfull.pop_back();
        if (nfull.size()) {
            int p = nfull.back();
            ans.push_back({1, p, 0});
            sta[p].push_back(x);
            pos[x] = p;
            continue;
        }
        vector <int> qwq;
        int y;
        while (1) {
            scanf("%d", &y);
            i++;
            if (y == x || sta[pos[y]].front() == y) break;
            qwq.push_back(y);
        }
        int cnt = 0, z = -1;
        if (y != x) z = sta[pos[y]].back();
        for (auto i : qwq) cnt += i == z;
        if (y == x || cnt % 2 == 1) {
            ans.push_back({1, ppos});
            for (auto i : qwq) {
                ans.push_back({1, pos[i]});
                if (sta[pos[i]].back() == i) sta[pos[i]].pop_back();
                else sta[pos[i]].push_back(i);
            }
            for (auto i : qwq) if (pos[i] && sta[pos[i]].back() != i) {
                nfull.push_back(pos[i]);
                pos[i] = 0;
            }
            if (y == x) ans.push_back({1, ppos});
            else {
                sta[ppos].push_back(x);
                nfull.push_back(ppos);
                pos[x] = ppos;
                ans.push_back({1, pos[y]});
                sta[ppos = pos[y]].pop_back();
                pos[y] = 0;
            }
        }
        else {
            ans.push_back({1, pos[y]});
            sta[pos[y]].push_back(x);
            pos[x] = pos[y];
            pos[z] = ppos;
            for (auto i : qwq) {
                ans.push_back({1, pos[i]});
                if (sta[pos[i]].size() && sta[pos[i]].back() == i) sta[pos[i]].pop_back();
                else sta[pos[i]].push_back(i);
            }
            for (auto i : qwq) if (pos[i] && sta[pos[i]].back() != i) {
                nfull.push_back(pos[i]);
                pos[i] = 0;
            }
            pos[z] = pos[y];
            ans.push_back({1, ppos});
            ans.push_back({2, ppos, pos[y]});
            sta[pos[y]].erase(sta[pos[y]].begin());
            pos[y] = 0;
        }
    }
    printf("%d\n", (int)ans.size());
    for (auto i : ans) {
        if (i.type == 1) printf("%d %d\n", i.type, i.s1);
        if (i.type == 2) printf("%d %d %d\n", i.type, i.s1, i.s2);
    }
}
int main() {
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while (T--) rmain();
}