#include <iostream>
#include <stack>
#include <queue>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
const int MAXN=2e6+2;
int a[MAXN];
int main()
{
    using namespace __gnu_pbds;
    freopen("meow.in", "r", stdin);
    freopen("meow.out","w",stdout);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        int n,m,k;
        cin >> n>>m>>k;
        for (int i=1;i<=m;i++){
            cin>>a[i];
        }
        vector<deque<int> > sts(n+1);
        tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> tr;
        for (int i =1; i<=n;i++){
            tr.insert(make_pair(0, i));
        }
        vector<unordered_set<int> > stTop(n+1), stDown(n+1);
        for (int i=1; i<=m;i++){
            int now = a[i];
            if (stTop[now].size()){
                int s = *stTop[now].begin();
                stTop[now].erase(s);
                sts[s].pop_back();
                tr.erase(tr.lower_bound(make_pair(sts[s].size()+1, s)));
                tr.insert(make_pair(s, sts[s].size()));
                cout << 1 << ' ' << s << '\n';
                continue;
            }
            if (stDown[now].size()){
                auto it = tr.find_by_order(0);
                int s1 = it->second;
                cout << 1 << ' ' << s1 << '\n';
                int s = *stDown[now].begin();
                stDown[now].erase(s);
                sts[s].pop_front();
                cout << 2 <<' ' << s1 << ' ' << s << '\n';
                tr.erase(tr.lower_bound(make_pair(sts[s].size()+1, s)));
                tr.insert(make_pair(s, sts[s].size()));
                continue;
            }
            auto it = tr.find_by_order(0);
            auto s = it->second;

            if (sts[s].size() != 0) {
                stTop[now].erase(sts[s].back());
            } else {
                stDown[now].insert(s);
            }

            stTop[now].insert(s);
            sts[s].push_back(now);
	    cout << 1 << ' ' << s << '\n';
            tr.erase(it);
            tr.insert(make_pair(sts[s].size(), s));
        }
    }
    return 0;
}

