#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e2 + 7;
int dp[MAX_N][MAX_N];
int T, n;

vector<int> hamilton(int l, int r) {
	if (l == r) return {l};
	int mid = (l + r) >> 1;
	vector<int> a = hamilton(l, mid);
	vector<int> b = hamilton(mid + 1, r);
	vector<int> res;
	int i = 0, j = 0, tmp;
	while (i < a.size() && j < b.size()) {
		printf("1 %d %d\n", a[i], b[j]);
		fflush(stdout);
		scanf("%d", &tmp);
		if (tmp) {
			res.push_back(a[i++]);
		} else {
			res.push_back(b[j++]);
		}
	}
	while (i < a.size()) res.push_back(a[i++]);
	while (j < b.size()) res.push_back(b[j++]);
	return res;
}

void work(int n) {
	vector<int> h = hamilton(0, n - 1);
	int p = n - 1, tmp;
	memset(dp, 0, sizeof dp);
	for (int i = 0; i < n; ++i) dp[i][i] = 1;
	for (int i = n - 1; i; --i) {
		if (i) dp[h[i - 1]][h[i]] = 1;
		if (p >= i) p = i - 1;
		while (p >= 0) {
			printf("2 %d %d ", h[i], p + 1);
			for (int j = 0; j <= p; ++j) printf("%d ", h[j]);
			puts("");
			fflush(stdout);
			scanf("%d", &tmp);
			if (tmp) {
				dp[h[i]][h[p--]] = 1;
			} else {
				break;
			}
		}
	}
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				dp[i][j] |= dp[i][k] & dp[k][j];
			}
		}
	}
	puts("3");
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			printf("%d", dp[i][j]);
		}
		puts("");
	}
	fflush(stdout);
	scanf("%d", &tmp);
}

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		work(n);
	}
	return 0;
}