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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;


int askOne(int a, int b) {
    cout<<"1 "<<a<<" "<<b<<endl;
    int res;
    cin>>res;
    assert(~res);
    return res; // return 1 if a-->b, aka a is before b
}
int askMany(int x, vector<int> s) {
    cout<<"2 ";
    cout<<x<<" ";
    cout<<s.size()<<" ";
    for (int i: s) cout<<i<<" ";
    cout<<endl;
    int res;
    cin>>res;
    assert(~res);
    return res;
}

vector<vector<int>> solve() {
    int n;
    cin>>n;
    vector<vector<int>> g(n, vector<int>(n, 1));

    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    stable_sort(p.begin(), p.end(), askOne);

    for (int i=n-1,ptr=n-2; i>=0; i--) {
	if (i==ptr) {
	    // p[i+1..n-1] can't reach p[0..i]
	    for (int k=i+1; k<n; k++) {
		for (int j=0; j<=i; j++) {
		    g[p[k]][p[j]] = 0;
		}
	    }
	    ptr--;
	}

	while (askMany(p[i],vector<int>(p.begin(),p.begin()+ptr+1))) {
	    ptr--;
	}
    }
    
    return g;
}

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

    int t; cin>>t;
    while (t--) {
	auto ret = solve();
	cout<<3<<endl;
	for (auto p: ret) {
	    for (int i: p) cout<<i;
	    cout<<endl;
	}
	int ok;
	cin>>ok;
	assert(~ok);
    }
    
    
    return 0;
}
