
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
bool cmp(const int &a,const int &b){
	cout<<1<<" "<<a<<" "<<b<<endl;//if a->b exists we add b to new path first since a->b and a->a_nxt exists
	int res;cin>>res;
	return res;
}
vector<int>p;
bool ask2(int x,int i){
	cout<<2<<" "<<x<<" "<<i+1<<" ";
	for(int ii=0;ii<=i;ii++)cout<<p[ii]<<" ";
	cout<<endl;
	int res;
	cin>>res;
	return res;
	
}
int main()
{
	//suppose we already have hamil path
	//two pointer from back,if we can extend back edge that mean we can travel to those node via whatever
	//constructing hamil path from mergesort is really smart : ) 
	
	int t;cin>>t;
	while(t--){
		int n;
		cin>>n;
		p.clear();
		for(int i=0;i<n;i++)p.pb(i);
		stable_sort(all(p),cmp);
		//cout<<"path :"<<'\n';
		//for(int x:p)cout<<x<<" ";
		//cout<<'\n';
		vii ans(n,vector<int>(n,1));
		int cur = n-2;
		for(int i=n-1;i>=0;i--){
			if(cur == i){ //none of the nodes from [cur+1,n] can reach [1,cur]
				for(int j=0;j<=cur;j++){
					for(int k=cur+1;k<n;k++){
						ans[p[k]][p[j]] = 0;
					}
				}
				cur--;
			}
			while(cur>=0 && ask2(p[i],cur))cur--;
		}
		cout<<3<<'\n';
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<ans[i][j];
			}
			cout<<endl;
		}
		int ok;cin>>ok;
		if(!ok)exit(0);
	}
}
