#include <bits/stdc++.h>
using namespace std;
const int N = 2000005,M = 1005;
namespace FIO
{
    const int S = 1 << 22;char buf[S];int ptr,len;
    inline int getch()
    {
        if (ptr == len) ptr = 0,len = fread(buf,1,S,stdin);
        if (ptr == len) return EOF;
        return buf[ptr++];
    }
}
template <typename T>
void read(T &num)
{
    int ch = FIO::getch();while (!isdigit(ch) && ch != '-') ch = FIO::getch();
    int fl = 1;if (ch == '-') fl = -1,ch = FIO::getch();
    while (isdigit(ch)) num = num * 10 + (ch - 48),ch = FIO::getch();
    num *= fl;
}
template <typename T>
void write(T num)
{
    if (num < 0) putchar('-'),num = -num;
    if (!num) {putchar('0');return;}
    static char buf[1024];int ptr = 0;
    while (num) buf[ptr++] = num % 10,num /= 10;
    while (ptr--) putchar(buf[ptr] + '0');
}
int n,m,kk,a[N];
int onbot[M],ontop[M],siz[M];deque<int> stk[1005];
set<int> st[M];
struct Op {int tp,x,y;};vector<Op> ans;
inline void delstk(int x)
{
    st[siz[x]].erase(x);if (stk[x].empty()) return;
    ontop[stk[x].back()] = 0;if (stk[x].size() > 1) onbot[stk[x][0]] = 0;
}
inline void updstk(int x)
{
    siz[x] = stk[x].size();
    if (stk[x].empty()) {st[siz[x]].insert(x);return;}
    ontop[stk[x].back()] = x;if (stk[x].size() > 1) onbot[stk[x][0]] = x;
    st[siz[x]].insert(x);
}
void dumpstk()
{
    
    cerr << "STK" << endl;
    for (int i = 1;i <= n;i++)
    {
        for (auto &j : stk[i]) cerr << j << ' ';
        cerr << endl;
    }
}
int main ()
{
    freopen("meow.in","r",stdin);
    freopen("meow.out","w",stdout);
    ios::sync_with_stdio(false);
    int T;cin >> T;
    while (T--)
    {
        cin >> n >> m >> kk;
        for (int i = 1;i <= m;i++) cin >> a[i];
        for (int i = 0;i <= n;i++) st[i].clear();
        for (int i = 1;i <= n;i++) stk[i].clear(),siz[i] = 0,updstk(i);
        int ptr = 1;ans.clear();
        while (ptr <= m)
        {
            cerr << "Ptr=" << ptr << endl;
            cerr << ontop[1] << endl;
            if (ontop[a[ptr]])
            {
                cerr << "A" << endl;
                int cur = ontop[a[ptr]];delstk(cur);
                ans.push_back({1,cur,0});stk[cur].pop_back();updstk(cur);
                ++ptr;continue;
            }
            if (onbot[a[ptr]])
            {
                cerr << "B" << endl;
                int cur = onbot[a[ptr]];delstk(cur);assert(!st[0].empty());
                int tt = *st[0].begin();
                // cerr << "PTR=" << ptr << ' ' << a[ptr] << ' ' << cur << ' ' << stk[cur][0] << endl;
                ans.push_back({1,tt,0});ans.push_back({2,cur,tt});stk[cur].pop_front();updstk(cur);
                ++ptr;continue;
            }
            if (st[0].size() > 1)
            {
                cerr << "C" << endl;
                int tt = *st[0].begin();delstk(tt);
                ans.push_back({1,tt,0});stk[tt].push_back(a[ptr]);updstk(tt);
                ++ptr;continue;
            }
            if (st[0].empty())
            {
                cerr << "D" << endl;
                assert(int(st[1].size()) == n);
                int tt = ptr + 1;while (tt <= m && !ontop[a[tt]]) ++tt;
                assert(tt <= m);cerr << "XX" << tt << endl;
                int targetstk = ontop[a[tt]];
                st[1].erase(targetstk);
                while (ptr < tt)
                {
                    if (ontop[a[ptr]])
                    {
                        int cur = ontop[a[ptr]];delstk(cur);
                        ans.push_back({1,cur,0});stk[cur].pop_back();updstk(cur);
                        ++ptr;continue;
                    }
                    int x = *st[1].begin();delstk(x);
                    ans.push_back({1,x,0});stk[x].push_back(a[ptr]);updstk(x);
                    ++ptr;continue;
                }
                st[1].insert(targetstk);continue;
            }
            if (!st[1].empty())
            {
                cerr << "E" << endl;
                int tt = *st[1].begin();delstk(tt);
                ans.push_back({1,tt,0});stk[tt].push_back(a[ptr]);updstk(tt);
                ++ptr;continue;
            }
            cerr << "F" << endl;
            assert(st[0].size() == 1);int targetstk = *st[0].begin();
            int curclr = a[ptr];
            int tt = ptr + 1;
            set<int> xorst;
            while (1)
            {
                if (curclr == a[tt] || onbot[a[tt]]) break;
                assert(ontop[a[tt]]);
                if (xorst.count(a[tt])) xorst.erase(a[tt]);else xorst.insert(a[tt]);
                if (int(xorst.size()) == n - 1) break;
                // cerr << "XX" << tt << endl;
                ++tt;
            }
            cerr << ptr << ' ' << tt << ' ' << onbot[a[tt]] << ' ' << stk[onbot[a[tt]]][1] << endl;
            for (auto &i : xorst) cerr << i << ' ';
            cerr << endl;
            assert(tt <= m);
            if (a[tt] == curclr || int(xorst.size()) == n - 1 || xorst.count(stk[onbot[a[tt]]][1]))
            {
                cerr << "HAHA" << ' ' << (a[tt] == curclr) << endl;
                delstk(targetstk);ans.push_back({1,targetstk,0});stk[targetstk].push_back(a[ptr]);
                updstk(targetstk);cerr << ontop[1] << endl;
                ++ptr;
                while (ptr < tt)
                {
                    if (ontop[a[ptr]])
                    {
                        int cur = ontop[a[ptr]];delstk(cur);
                        ans.push_back({1,cur,0});stk[cur].pop_back();updstk(cur);
                        cerr << "PUSH with RM" << cur << ' ' << a[ptr] << endl; 
                        ++ptr;continue;
                    }
                    int x = *st[1].begin();
                    delstk(x);
                    // cerr << "PUSH " << x << ' ' << a[ptr] << endl; 
                    ans.push_back({1,x,0});stk[x].push_back(a[ptr]);updstk(x);
                    ++ptr;continue;
                }
                // cerr << "STK" << endl;
                // for (int i = 1;i <= n;i++)
                // {
                //     for (auto &j : stk[i]) cerr << j << ' ';
                //     cerr << endl;
                // }
                continue;
            }
            static int ID[N];for (int i = ptr + 1;i < tt;i++) ID[a[i]] = ontop[a[i]];
            int pos = onbot[a[tt]];delstk(pos);ans.push_back({1,pos,0});stk[pos].push_back(a[ptr]);
            updstk(pos);
            ++ptr;cerr << "XX" << endl;
            while (ptr < tt)
            {
                if (ontop[a[ptr]])
                {
                    int cur = ontop[a[ptr]];delstk(cur);
                    ans.push_back({1,cur,0});stk[cur].pop_back();updstk(cur);
                    cerr << "RM" << a[ptr] << endl;
                    ++ptr;continue;
                }
                int x = ID[a[ptr]];delstk(x);
                ans.push_back({1,x,0});stk[x].push_back(a[ptr]);updstk(x);
                ++ptr;continue;
            }
        }
        for (int i = 1;i <= n;i++) assert(stk[i].empty());
        cout << ans.size() << '\n';
        for (auto &i : ans)
            if (i.tp == 1) cout << i.tp << ' ' << i.x << '\n';
            else cout << i.tp << ' ' << i.x << ' ' << i.y << '\n';
    }
    return 0;
}
/*
3 18 5
5 4 5 2 5 1 3 2 5 2 2 2 5 1 4 5 3 2 
*/