#include <bits/stdc++.h>
using namespace std;
int T, n, m, k, a[105], op, stackPointer=1, cardPointer; //datasets, amount of stacks, amount of cards, variants of cards, cards, oprations
queue<int> Stack[305];  //limited by n
struct o{
    int type, stack1, stack2;
}operations[1010];
bool stacksEmpty() {
    for(int i=1; i<=n; i++) {
        if(Stack[i].empty() == false) {
            return false;
        }
    }
    return true;
}//~~just put the m cards in the stack will cost m operations, no need to check that~~
// void search(int stack) { //check op >= m to avoid the situation: search hasn't started
//     // exit(0);
//     // cout << "Alive" << endl;
//     if(op >= m && op <= 2*m && stacksEmpty()) { 
//         cout << op << endl; //Output Line 1
//         while(op!=0) {
//             if(operations[op].type==1) {
//                 cout << 1 << ' ' << operations[op].stack1 << endl;
//             } else if(operations[op].type==2) {
//                 cout << 2 << ' ' << operations[op].stack1 << operations[op].stack2 << endl;
//             } else {
//                 cout << "[Error] Unknown Operation Type " << operations[op].type << endl;
//             }
//         }
//         return;
//     } 
//     if(op >= 2*m) {      //exceeded
//         return;
//     }
//     if(Stack[1].front()==Stack[2].front()) {
//         operations[++op].type=2;
//         operations[op].stack1=1;
//         operations[op].stack2=2;
//     }
//     if(Stack[1].front()==Stack[3].front()) {
//         operations[++op].type=2;
//         operations[op].stack1=1;
//         operations[op].stack2=3;
//     }
//     if(Stack[2].front()==Stack[3].front()) {
//         operations[++op].type=2;
//         operations[op].stack1=2;
//         operations[op].stack2=3;
//     }
//     if(stackPointer==4) {
//         stackPointer=1;
//     }
//     Stack[stackPointer].push(a[++cardPointer]);
// }
int main() {
    freopen("meow2.in", "r", stdin);
    // freopen("meow.out", "w", stdout);
    cin >> T;           //amount of data
    while(T--) {
        cout << "[Data] " << T+1 << endl;
        op = 0;
        
        cin >> n >> m >> k;  //n<=300
        for(int i=1; i<=m; i++) {
            cin >> a[i];
        }
        cardPointer=m;
        while(cardPointer <= m) {
            if(op >= m && op <= 2*m && stacksEmpty()) { 
                cout << op << endl; //Output Line 1
                while(op!=0) {
                    if(operations[op].type==1) {
                        cout << 1 << ' ' << operations[op].stack1 << endl;
                    } else if(operations[op].type==2) {
                        cout << 2 << ' ' << operations[op].stack1 << operations[op].stack2 << endl;
                    } else {
                        cout << "[Error] Unknown Operation Type " << operations[op].type << endl;
                    }
                }
                continue;
            } 
            if(op >= 2*m) {      //exceeded
                continue;        //always continue; never break;
            }
            if(Stack[1].front()==Stack[2].front()) {
                operations[++op].type=2;
                operations[op].stack1=1;
                operations[op].stack2=2;
                Stack[1].pop();
                Stack[2].pop();
            }
            if(Stack[1].front()==Stack[3].front()) {
                operations[++op].type=2;
                operations[op].stack1=1;
                operations[op].stack2=3;
                Stack[1].pop();
                Stack[3].pop();
            }
            if(Stack[2].front()==Stack[3].front()) {
                operations[++op].type=2;
                operations[op].stack1=2;
                operations[op].stack2=3;
                Stack[2].pop();
                Stack[3].pop();
            }
            if(stackPointer==4) {
                stackPointer=1;
            }
            Stack[stackPointer++].push(a[--cardPointer]);
            cout << "[Debug] pushed " << a[cardPointer] << " into Stack[" << stackPointer-1 << "]" << endl;
        }
        // cout << "Alive" << endl;
    }
    return 0;
}