#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline ll rd(){
    ll x = 0;bool f = true;char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')f = false;
        c = getchar();
    }
    while(c <= '9' && c >= '0'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return f ? x : -x;
}
const int M = 2e6 + 10, N = 3e2 + 10;

int T, n, m, k;
int a[M];
struct Ans{
    int op;
    int sta1, sta2;
}ans[M];

void solve1(){
    int tot = 0;
    int que[N][2];
    memset(que, 0, sizeof(que));
    for(int i = 1; i <= m; ++i){
        int sta = (a[i] + 1) / 2;
        if(!que[sta][0]){
            ans[++tot].op = 1;
            ans[tot].sta1 = sta;
            que[sta][0] = a[i];
        }else if(!que[sta][1]){
            if(que[sta][0] == a[i]){
                ans[++tot].op = 1;
                ans[tot].sta1 = sta;
                que[sta][0] = 0;
            }else{
                ans[++tot].op = 1;
                ans[tot].sta1 = sta;
                que[sta][1] = a[i];
            }
        }else{
            if(que[sta][1] == a[i]){
                ans[++tot].op = 1;
                ans[tot].sta1 = sta;
                que[sta][1] = 0;
            }else{
                ans[++tot].op = 1;
                ans[tot].sta1 = n;
                ans[++tot].op = 2;
                ans[tot].sta1 = sta;
                ans[tot].sta2 = n;
                que[sta][0] = que[sta][1];
                que[sta][1] = 0;
            }
        }
    }
    printf("%d\n", tot);
    for(int i = 1; i <= tot; ++i){
        if(ans[i].op == 1)
            printf("1 %d\n", ans[i].sta1);
        else    
            printf("2 %d %d\n", ans[i].sta1, ans[i].sta2);
    }
    return ;
}

void solve2(){
    int tot = 0;
    deque<int>q1, q2;
    for(int i = 1; i <= m; ++i){
        if(a[i] == a[i + 1]){
            ans[++tot].op = 1;
            ans[tot].sta1 = 1;
            ans[++tot].op = 1;
            ans[tot].sta1 = 1;
        }

        if(q1.empty() && q2.empty()){
            ans[++tot].op = 1;
            ans[tot].sta1 = 1;
            q1.push_back(a[i]);
        }

        if(q1.empty()){
            if(q2.front() == a[i]){
                ans[++tot].op = 1;
                ans[tot].sta1 = 1;
                ans[++tot].op = 2;
                ans[tot].sta1 = 1;
                ans[tot].sta2 = 2;
                q2.pop_front();
            }else if(q2.back() == a[i]){
                ans[++tot].op = 1;
                ans[tot].sta1 = 2;
                q2.pop_back();
            }else{
                if(a[i + 1] == q2.front()){
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 2;
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 1;
                    ans[++tot].op = 2;
                    ans[tot].sta1 = 1;
                    ans[tot].sta2 = 2;
                    q2.push_back(a[i]);
                    q2.pop_front();
                    
                }else{
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 1;
                    q1.push_front(a[i]);
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 2;
                    q2.pop_back();
                }++i;
            }
        }else if(q2.empty()){
            if(q1.front() == a[i]){
                ans[++tot].op = 1;
                ans[tot].sta1 = 2;
                ans[++tot].op = 2;
                ans[tot].sta1 = 1;
                ans[tot].sta2 = 2;
                q1.pop_front();
            }else if(q1.back() == a[i]){
                ans[++tot].op = 1;
                ans[tot].sta1 = 1;
                q1.pop_back();
            }else{
                if(a[i + 1] == q1.front()){
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 1;
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 2;
                    ans[++tot].op = 2;
                    ans[tot].sta1 = 1;
                    ans[tot].sta2 = 2;
                    q1.push_back(a[i]);
                    q1.pop_front();
                }else{
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 2;
                    q2.push_front(a[i]);
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 1;
                    q1.pop_back();
                }
                ++i;
            }
        }else{
            if(a[i] == q1.back()){
                q1.pop_back();
                ans[++tot].op = 1;
                ans[tot].sta1 = 1;
            }else if(a[i] == q2.back()){
                q2.pop_back();
                ans[++tot].op = 1;
                ans[tot].sta1 = 2;
            }else{
                if(a[i + 1] == q1.back()){
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 2;
                    q2.push_back(a[i]);
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 1;
                    q1.pop_front();
                    
                }else{
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 1;
                    q1.push_back(a[i]);
                    ans[++tot].op = 1;
                    ans[tot].sta1 = 2;
                    q2.pop_front();
                }
            }
        }
    }

    printf("%d\n", tot);
    for(int i = 1; i <= tot; ++i){
        if(ans[i].op == 1)
            printf("1 %d\n", ans[i].sta1);
        else    
            printf("2 %d %d\n", ans[i].sta1, ans[i].sta2);
    }
    return;
}

int main(){
    // freopen("E:/test/test.in", "r", stdin);
    // freopen("E:/test/test.out", "w", stdout);
    freopen("meow.in", "r", stdin);
    freopen("meow.out", "w", stdout);
    T = rd();
    while(T--){
        n = rd(), m = rd(), k = rd();
        a[n + 1] = 0;
        for(int i = 1; i <= m; ++i)a[i] = rd();
        if(k == 2 * n - 2)
            solve1();
        else
            solve2();
    }

    return 0;
}