#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define sfor(i, h, t) for(int i = (h); i <= (t); ++i)
#define dfor(i, t, h) for(int i = (t); i >= (h); --i)
#define il inline
#define ms(x, i) memset(x, i, sizeof x)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ldb;
const int MAXN = 304;
int T;
int N, M, K;
il string &operator+=(string &s, int _x) {
    int x = _x;
    vector<char> _v;
    for(; x; x /= 10)
        _v.push_back(char(x % 10 + 48));
    for(; _v.size(); _v.pop_back())
        s += _v.back();
    return s;
}
queue<string> cmd;
il void prt(void) {
    cout << cmd.size() << '\n';
    while(cmd.size()) {
        cout << cmd.front() << '\n';
        cmd.pop();
    }
}
il void sumcmd(int s) {
    string str = "1 ";
    str += s;
    cmd.push(str);
}
il void sumcmd(int s1, int s2) {
    string str = "2 ";
    str += s1;
    str += ' ';
    str += s2;
    cmd.push(str);
}
il void subtask1(void) {
    int pos[MAXN << 1];
    sfor(i, 1, K)
        pos[i] = 0;
    int pic, pic_;
    while(M--) {
        cin >> pic;
        // cerr << pos[1] << ' ' << pos[2] << '\n';
        pic_ = pic < N ? (pic + N - 1) : (pic - N + 1);
        if(!pos[pic]) {
            sumcmd(min(pic, pic_));
            pos[pic] = 1;
            if(pos[pic_])
                pos[pic_] = -1;
        }
        else {
            if(pos[pic] == -1) {
                sumcmd(N);
                // cout << "1 " << N << '\n';
                sumcmd(min(pic, pic_), N);
                // cout << "2 " << min(pic, pic_) << ' ' << N << '\n';
                pos[pic] = 0;
            }
            else {
                sumcmd(min(pic, pic_));
                // cout << "1 " << min(pic, pic_) << '\n';
                pos[pic] = 0;
                if(pos[pic_])
                    pos[pic_] = 1;
            }
        }
    }
    prt();
}
deque<int> DQ;
il void subtask2(void) {
    int pic = 0, pic_;
    sfor(i, 1, M) {
        if(!pic && i < M) {
            cin >> pic;
            ++i;
        }
        cin >> pic_;
        if(!pic) {
            pic = pic_;
            pic_ = 0;
        }
        // cerr << pic << ' ' << pic_ << ' ';
        if(DQ.empty()) {
            // cerr << "empty\n";
            sumcmd(1);
            DQ.push_back(pic);
            pic = pic_;
            pic_ = 0;
            continue;
        }
        if(DQ.front() == pic) {
            // cerr << "1,1bot\n";
            sumcmd(2);
            sumcmd(1, 2);
            DQ.pop_front();
            pic = pic_;
            pic_ = 0;
            continue;
        }
        if(DQ.back() == pic) {
            // cerr << "1,1top\n";
            sumcmd(1);
            DQ.pop_back();
            pic = pic_;
            pic_ = 0;
            continue;
        }
        if(DQ.front() == pic_) {
            // cerr << "2,1bot\n" << DQ.front() << '\n';
            sumcmd(1);
            DQ.push_back(pic);
            sumcmd(2);
            sumcmd(1, 2);
            DQ.pop_front();
            pic = pic_ = 0;
            continue;
        }
        if(pic == pic_) {
            // cerr << "1=2\n";
            sumcmd(1);
            sumcmd(1);
            pic = pic_ = 0;
            continue;
        }
        // cerr << "x\n";
        sumcmd(1);
        DQ.push_back(pic);
        pic = pic_;
        pic_ = 0;
    }
    prt();
}
deque<int> dq[3];
int pic[16];
il void solve3(int typ, bool f) {
    for(int i = 1; i <= M; ++i, typ /= 3) {
        if(f)
            sumcmd(typ % 3 + 1);
        // cerr << typ << '\n';
        if(dq[typ % 3].empty()) {
            if(dq[(typ + 1) % 3].size() && dq[(typ + 1) % 3].front() == pic[i]) {
                if(f)
                    sumcmd(typ % 3 + 1, (typ + 1) % 3 + 1);
                dq[(typ + 1) % 3].pop_front();
                continue;
            }
            if(dq[(typ + 2) % 3].size() && dq[(typ + 2) % 3].front() == pic[i]) {
                if(f)
                    sumcmd(typ % 3 + 1, (typ + 2) % 3 + 1);
                dq[(typ + 2) % 3].pop_front();
                continue;
            }
            dq[typ % 3].push_back(pic[i]);
            continue;
        }
        if(dq[typ % 3].back() == pic[i]) {
            dq[typ % 3].pop_back();
            continue;
        }
        dq[typ % 3].push_back(pic[i]);
    }
}
il void subtask3(void) {
    int maxtyp = 1;
    sfor(i, 1, M) {
        cin >> pic[i];
        maxtyp *= 3;
    }
    sfor(typ, 0, maxtyp) {
        // cerr << typ << '\n';
        dq[0].clear();
        dq[1].clear();
        dq[2].clear();
        solve3(typ, 0);
        if(dq[0].empty() && dq[1].empty() && dq[2].empty()) {
            solve3(typ, 1);
            prt();
            return;
        }
    }
}
signed main(void) {
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> T;
    sfor(T_, 1, T) {
        cin >> N >> M >> K;
        if(T % 10 == 1)
            subtask1();
        if(T % 10 == 2)
            subtask2();
        if(T % 10 == 3)
            subtask3();
    }
    return !bool(cout << '\n');
}