#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline int read() {
    char c; bool f = true;
    while (!isdigit(c = getchar())) f = c != '-';
    int x = c ^ 48;
    while (isdigit(c = getchar())) x = x * 10 + (c ^ 48);
    return f ? x : -x;
}

const int N = 310;

int T, n, m, k;

int a[N];
int pos[N];
deque<int> stk[N];



int main() {
    srand(time(NULL));
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);
    T = read();
    while (T--) {
        memset(pos, 0, sizeof(pos));
        n = read(); m = read(); k = read();
        for (int i = 1; i <= n; i++) stk[i].clear();
        for (int i = 1; i <= m; i++) {
            a[i] = read();
        }

        for (int i = 1; i <= m; i++) {
            if (!pos[a[i]]) {
                bool findd = false;
                for (int j = 1; j <= n; j++) {
                    if (stk[j].empty() || stk[j].front() == stk[j].back()) {
                        stk[j].push_back(a[i]);
                        pos[a[i]] = j;
                        printf("1 %d\n", j);
                        findd = true;
                        break;
                    }
                }
                if (!findd) {
                    int to = rand() % n + 1;
                    pos[stk[to].back()] = 0;
                    stk[to].push_back(a[i]);
                    pos[a[i]] = to;
                    printf("1 %d\n", to);
                }
            } else {
                if (stk[pos[a[i]]].back() == a[i]) {
                    printf("1 %d\n", pos[a[i]]);
                    stk[pos[a[i]]].pop_back();
                    if (stk[pos[a[i]]].empty() || stk[pos[a[i]]].back() != a[i]) {
                        pos[a[i]] = 0;
                    }
                } else {
                    for (int j = 1; j <= n; j++) {
                        if (stk[j].empty()) {
                            printf("1 %d\n", j);
                            printf("2 %d %d\n", j, pos[a[i]]);
                            break;
                        }
                    }
                    stk[pos[a[i]]].pop_front();
                    if (stk[pos[a[i]]].empty() || stk[pos[a[i]]].front() != a[i]) {
                        pos[a[i]] = 0;
                    }
                }
            }
        }
    }
    return 0;
}
/*
1
2 4 2
1 2 1 2
*/