#include <iostream>
#include <vector>
#include <algorithm>
#define int int64_t
using namespace std;

bool query1(int a, int b)
{
    cout << "1 " << a << " " << b << '\n';
    int ans;
    cin >> ans;
    return ans == 1;
}

bool query2(int x, vector<int>& s)
{
    cout << "2 " << x << " " << s.size() << " ";
    for(int el : s) cout << el << " ";
    cout << '\n';
    int ans;
    cin >> ans;
    return ans == 1;
}

vector<int> insert(vector<int> vec, int x, int pos)
{
    vector<int> ans;
    for(int i = 0; i < vec.size(); i ++)
    {
        if(i == pos) ans.push_back(x);
        ans.push_back(vec[i]);
    }
    return ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    
    int t;
    cin >> t;
    for(int cse = 0; cse < t; cse ++)
    {
        vector<int> vec;
        int n; 
        cin >> n;
        vec = {0};
        for(int i = 1; i < n; i ++)
        {
            if(query1(i, vec.back())) vec.push_back(i);
            else if(query1(vec[0], i)) vec = insert(vec, i, 0);
            else
            {
                int lo = 0, hi = vec.size() - 1;
                while(lo + 1 < hi)
                {
                    int m = (hi + lo) / 2;
                    if(query1(i, vec[m])) lo = m;
                    else hi = m;
                }
                vec = insert(vec, i, hi);
            }
        } 

        int zu = 0;
        vector<int> zuvec(n);
        for(int i = 0; i < n; i ++)
        {
            bool found = true;
            zu = max(zu, i);
            while(found && zu < n - 1)
            {
                vector<int> qvec;
                for(int j = zu + 1; j < n; j ++) qvec.push_back(vec[j]);
                if(query2(vec[i], qvec)) zu ++;
                else found = false;
            }
            zuvec[i] = zu;
        }

        vector<int> zuvec2(n);
        int last = n - 1;
        for(int i = n - 1; i >= 0; i --)
        {
            if(zuvec[i] > i) zuvec2[i] = last;
            else
            {
                zuvec2[i] = i;
                last = i;
            } 
        }

        for(int i = 0; i < n; i ++) cerr << vec[i] << " " << zuvec2[i] << '\n';

        vector<vector<bool> > ansvec(n, vector<bool> (n));
        for(int i = 0; i < n; i ++)
        {
            for(int j = i; j >= 0; j --) ansvec[vec[i]][vec[j]] = true;
            for(int j = i; j <= zuvec2[i]; j ++) ansvec[vec[i]][vec[j]] = true;
        }

        cout << "3\n";
        for(int i = 0; i < n; i ++)
        {
            for(int j = 0; j < n; j ++)
            {
                cout << ansvec[i][j];
            }
            cout << '\n';
        }
        cin >> n;

    }
}

