#include <bits/stdc++.h>

using namespace std;

#define dbg(x...) \
    do {          \
        cout << #x << " -> "; \
        err(x);              \
    } while (0)

void err() {
    cout << endl;
}

template<class T, class... Ts>
void err(const T &arg, const Ts &... args) {
    cout << arg << ' ';
    err(args...);
}

typedef long long ll;
typedef pair<int, int> pi;

const int maxn = 105;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;

int e[maxn][maxn];
int mG[maxn][maxn];
int G[maxn][maxn];
int n;

void init() {
    for (int i = 0; i < n; i++) {
        char s[maxn];
        scanf("%s", s);
        for (int j = 0; j < n; j++) {
            e[i][j] = s[j] - '0';
            mG[i][j] = e[i][j];
        }
    }
    for (int i = 0; i < n; i++) e[i][i] = mG[i][i] = 1;
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                mG[i][j] |= (mG[i][k] & mG[k][j]);
            }
        }
    }
}

bool ans1(int u, int v) {
    printf("1 %d %d\n", u, v);
    return e[u][v] == 1;
}

bool ans2(int x, vector<int> &vec) {
    printf("2 %d %d\n", x, (int) vec.size());
    for (int i : vec) {
        printf("%d ", i);
    }
    puts("");
    bool ret = false;
    for (int i : vec) {
        assert(i != x);
        ret |= (e[x][i] == 1);
    }
    return ret;
}

bool check() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (G[i][j] != mG[i][j]) return false;
        }
    }
    return true;
}

bool ask1(int u, int v) {
    printf("1 %d %d\n", u, v);
    fflush(stdout);
    int ret;
    scanf("%d", &ret);
    return ret == 1;
}

void solve(vector<int> &vec) {
    if (vec.empty()) return;
    int len = vec.size();
    int x = vec[rand() % len];
    vector<int> pre, suf;
    for (int i : vec) {
        if (i == x) continue;
        if (ask1(i, x)) {
            pre.push_back(i);
        } else {
            suf.push_back(i);
        }
    }
    solve(pre);
    solve(suf);

    vec.clear();
    for (int i : pre) vec.push_back(i);
    vec.push_back(x);
    for (int i : suf) vec.push_back(i);
}

bool ask2(int x, vector<int> &vec) {
    if (vec.empty()) return false;
    printf("2 %d %d", x, (int) vec.size());
    for (int i : vec) {
        printf(" %d", i);
    }
    puts("");
    fflush(stdout);
    int ret;
    scanf("%d", &ret);
    return ret == 1;
}

int l[maxn];

void run() {
    scanf("%d", &n);
//    init();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            G[i][j] = i == j ? 1 : 0;
        }
    }
    vector<int> vec;
    for (int i = 0; i < n; i++) vec.push_back(i);
    solve(vec);
//    for (int i : vec) dbg(i);
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            int u = vec[i], v = vec[j];
            G[u][v] = 1;
        }
    }
    int cur = n - 2;
    vector<int> tmp;
    for (int i = 0; i <= cur; i++) tmp.push_back(vec[i]);
    for (int i = n - 1; i >= 0; i--) {
        if (cur == i) cur--, tmp.pop_back();
        while (cur >= 0 && ask2(vec[i], tmp)) {
            cur--;
            tmp.pop_back();
        }
        l[i] = cur + 1;
    }
    for (int i = 0; i < n; i++) {
        for (int j = l[i]; j < i; j++) {
            l[i] = min(l[i], l[j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = l[i]; j < i; j++) {
            G[vec[i]][vec[j]] = 1;
        }
    }
    puts("3");
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            printf("%d", G[i][j]);
        }
        puts("");
    }
    fflush(stdout);
    int ans;
    scanf("%d", &ans);
    assert(ans == 1);
//    assert(check());
}

/*
4
0011
1001
0101
0000

4
0010
1011
0000
1010
*/

int main() {
    srand(0);

    int T = 1;
    scanf("%d", &T);
    while (T--) {
        run();
    }

    return 0;
}