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

int ask(int u, int v) {
    cout << "1 " << u << " " << v << endl;
    cout.flush();
    int res;
    cin >> res;
    return res;
}

vector<int> merge(vector<int> a, vector<int> b) {
    vector<int> c;
    int ia = 0, ib = 0;
    while (ia < a.size() && ib < b.size()) {
        if (ask(a[ia], b[ib])) c.push_back(a[ia++]);
        else c.push_back(b[ib++]);
    }
    while (ia < a.size()) c.push_back(a[ia++]);
    while (ib < b.size()) c.push_back(b[ib++]);
    for (auto &x : c) cerr << x << " ";
    cerr << " ord\n";
    cerr << a.size() << " " << b.size() << "\n";
    return c;
}

vector<int> mSort(vector<int> l) {
    if (l.size() == 1) return l;
    vector<int> r;
    int n = l.size();
    while (l.size() > n / 2) {
        r.push_back(l.back());
        l.pop_back();
    }
    l = mSort(l); r = mSort(r);
    return merge(l, r);
}

int q2(int i, vector<int> ids) {
    cout << "2 " << i << " " << ids.size() << " ";
    for (auto &x : ids) cout << x << " ";
    cout << "\n";
    cout.flush();

    int res;
    cin >> res;
    return res;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;

        vector<int> ids;
        for (int i = 0; i < n; i++) ids.push_back(i);
        ids = mSort(ids);

        for (auto &x : ids) cerr << x << " ";
        cerr << " ids\n";
        vector<string> res(n, string(n, '0'));
        for (int i = 0; i < n; i++) 
            for (int j = i; j < n; j++)
                res[ids[i]][ids[j]] = '1';
        
        auto a = ids;
        int to = n - 1;
        for (int i = n - 1; i >= 0; i--) {
            while (!a.empty() && (i < a.size() || q2(ids[i], a))) a.pop_back();
            if (i == a.size()) {
                for (int j = i; j <= to; j++)
                    for (int k = i; k <= to; k++)
                        res[ids[j]][ids[k]] = '1';
                to = i - 1;    
            }
        }

        cout << "3\n";
        for (auto &s : res) cout << s << "\n";
        cout.flush();
        
        int r;
        cin >> r;
        assert(r == 1);
    }
}
