#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <cassert>
#include <algorithm>

//#define TEST 1
#define Maxn 1000000007
typedef long long ll;

using namespace std;

int query1(int x, int y)
{
    printf("1 %d %d\n", x, y);
    fflush(stdout);
    int res;
    scanf("%d", &res);
    if (res==-1) assert(false);
    return res;
}

int query2(int x, vector<int> &s, int k)
{
    printf("2 %d %d", x, k+1);
    for (int i=0; i<=k; i++) printf(" %d", s[i]);
    printf("\n");
    fflush(stdout);
    int res;
    scanf("%d", &res);
    if (res==-1) assert(false);
    return res;
}

void merge(vector<int> &arr, int l, int r)
{
    if (l + 1 >= r) return;
    int mid = (l+r)/2;
    merge(arr, l, mid);
    merge(arr, mid, r);
    int i = l, j=mid;
    vector<int> barr;
    barr.clear();
    while (i<mid && j<r)
    {
        if (query1(arr[i], arr[j])==1)
            barr.push_back(arr[i++]);
        else
            barr.push_back(arr[j++]);
    }
    while (i<mid) barr.push_back(arr[i++]);
    while (j<r) barr.push_back(arr[j++]);
    for (int i=l; i<r; i++) arr[i] = barr[i-l];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int tc;
    cin>>tc;
    while(tc--)
    {
        int n;
        scanf("%d", &n);
        vector<int> arr;
        arr.clear();
        for (int i=0; i<n; i++) arr.push_back(i);
        merge(arr, 0, n);
        //printf("Path = ");
        //for (int x: arr) printf("%d ", x); printf("\n");
        //
        vector<vector<int> > f;
        vector<int> anc, minUp;
        f.resize(n);
        anc.resize(n);
        for (int i=0; i<n; i++)
        {
            f[i].resize(n);
            for (int j=0; j<n; j++) f[i][j] = 0;
        }
        int up = n-1;
        for (int x=n-1; x>=0; x--)
        {
            while(up>=x) up--;
            while (up>=0 && query2(arr[x], arr, up)>0) up--;
            anc[x] = up+1;
        }

        bool flag = true;
        while (flag)
        {
            flag = false;
            for (int i=0; i<n; i++)
            {
                for (int j=anc[i]; j<i; j++)
                    if (anc[i]>anc[j])
                {
                    anc[i] = anc[j];
                    flag = true;
                }
            }
        }

        for (int x=0; x<n; x++)
        {
            for (int y=anc[x]; y<n; y++)
                f[arr[x]][arr[y]] = 1;
        }

        printf("3\n");
        for (int i=0; i<n; i++)
        {
            for (int j=0; j<n; j++) printf("%d", f[i][j]);
            printf("\n");
        }
        fflush(stdout);
        int res;
        scanf("%d", &res);
        if (res==-1) exit(0);
    }
    fflush(stdout);
    return 0;
}