// This Code was made by Chinese_zjc_.
#include <bits/stdc++.h>
struct oper
{
    bool add;
    int s1, s2;
};
std::deque<int> sta[305];
std::vector<int> app[605];
std::set<int> t[2];
int T, n, m, k, a[2000005], cur, in[605];
std::vector<oper> ans;
void op1(int x)
{
    ++cur;
    // assert(cur <= m);
    ans.push_back({true, x});
    if (!sta[x].empty() && sta[x].back() == a[cur])
        sta[x].pop_back();
    else
        sta[x].push_back(a[cur]);
}
void op2(int x, int y)
{
    if (sta[x].front() == sta[y].front())
    {
        ans.push_back({false, x, y});
        sta[x].pop_front();
        sta[y].pop_front();
    }
}
int query(int id, int l, int r)
{
    return std::upper_bound(app[id].begin(), app[id].end(), r) -
           std::lower_bound(app[id].begin(), app[id].end(), l);
}
signed 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;
        cur = 0;
        ans.clear();
        for (int i = 1; i <= k; ++i)
            app[i].clear();
        for (int i = 1; i <= m; ++i)
            std::cin >> a[i], app[a[i]].push_back(i);
        t[0].clear();
        t[1].clear();
        for (int i = 1; i <= n; ++i)
            t[0].insert(i);
        for (int i = 1; i <= m; ++i)
        {
            std::set<int> upd;
            upd.insert(a[i]);
            if (int &p = in[a[i]])
                if (sta[p].back() == a[i])
                    op1(p);
                else
                {
                    op1(*t[0].begin());
                    op2(*t[0].begin(), p);
                }
            else
            {
                if (t[0].size() > 1)
                    op1(p = *t[0].begin());
                else if (t[1].size())
                    op1(p = *t[1].begin());
                else
                {
                    // for (int j = 1; j <= n; ++j)
                    // {
                    //     for (auto k : sta[j])
                    //         std::cout << k << ' ';
                    //     std::cout << std::endl;
                    // }
                    for (int j = i + 1; j <= m; ++j)
                    {
                        upd.insert(a[j]);
                        if (int q = in[a[j]])
                        {
                            if (sta[q].front() == a[j])
                            {
                                int up = sta[q].back();
                                if (query(up, i, j) & 1)
                                {
                                    in[a[i]] = *t[0].begin();
                                    while (i <= j)
                                    {
                                        op1(in[a[i]]);
                                        ++i;
                                    }
                                    --i;
                                }
                                else
                                {
                                    in[a[i]] = q;
                                    while (i < j)
                                    {
                                        op1(in[a[i]]);
                                        ++i;
                                    }
                                    op1(*t[0].begin());
                                    op2(*t[0].begin(), q);
                                }
                                break;
                            }
                        }
                        else
                        {
                            in[a[i]] = *t[0].begin();
                            while (i <= j)
                            {
                                op1(in[a[i]]);
                                ++i;
                            }
                            --i;
                            break;
                        }
                    }
                }
            }
            for (auto j : upd)
            {
                for (int k = 0; k != 2; ++k)
                    if (int(sta[in[j]].size()) == k)
                        t[k].insert(in[j]);
                    else
                        t[k].erase(in[j]);
                if (!std::count(sta[in[j]].begin(), sta[in[j]].end(), j))
                    in[j] = 0;
            }
            upd.clear();
            // for (int j = 1; j <= k; ++j)
            //     assert(!in[j] || std::count(sta[in[j]].begin(), sta[in[j]].end(), j));
            // for (int j = 1; j <= n; ++j)
            //     for (int k = 0; k != 2; ++k)
            //         assert(int(sta[j].size()) != k || t[k].count(j));
        }
        std::cout << ans.size() << '\n';
        for (auto i : ans)
            if (i.add)
                std::cout << 1 << ' ' << i.s1 << '\n';
            else
                std::cout << 2 << ' ' << i.s1 << ' ' << i.s2 << '\n';
        // assert(cur == m);
        // for (int i = 1; i <= n; ++i)
        //     assert(sta[i].empty());
    }
    return 0;
}