#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int ask(int x , int i , vi v){
	cout << 2 <<" " << x  <<" " << i << " ";
	for(int j = 0 ; j < i ; j ++){
		cout << v[j]  <<" ";
	}
	cout << endl;
	int ans;
	cin >> ans;
	return ans;
}





int32_t main(){
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> v;
		for(int i = 0 ; i < n; i ++)
			v.push_back(i);
		stable_sort(all(v) , [&](int a , int b){
			cout << 1 <<" " << a <<" " << b << endl;
			int ans;
			cin >> ans;
			return ans;
		});
		vector< vector<char> > ans(n, vector<char>(n,'0'));
		for(int i = 0 ; i < n ; i ++){
			for(int j = i ; j < n; j ++){
				ans[v[i]][v[j]] = '1';
			}
		}
		int pr = n-1;
		vector< vector<int> > g(n);
		for(int i = 0 ; i < n - 1; i ++)
			g[v[i]].push_back(v[i+1]);
		for(int i = n - 1 ; i >= 0 ; i --){
			pr = min(pr, i);
			while(pr > 0 && ask(v[i] , pr , v)){
				pr -- ;
			}
			g[v[i]].push_back(v[pr]);
		}
		vector< vector<bool> > vis(n , vector<bool> (n));
		for(int i = 0 ; i< n; i ++){
			queue<int> q;
			q.push(i);
			while(sz(q)){
				auto u = q.front();
				q.pop();
				if(vis[i][u])
					continue;
				vis[i][u] = true;
				for(auto w : g[u])
					if(!vis[i][w])
						q.push(w);
			}
		}
		cout << 3 << endl;
		for(int i = 0; i < n; i ++){
			for(int j = 0; j < n; j ++)
				cout << (vis[i][j] ? 1 : 0);
			cout << endl;
		}
		int ansx;
		cin >> ansx;
		assert(ansx != -1);
	}
	exit(0);
}