#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e5+69, INF=2e9+6969;

int qq;

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n,t[R];
		string s;
		scanf("%lld", &n);
		for(int i=0;i<n;++i) scanf("%lld", &t[i]);
		cin >> s;
		vector <ll> base;
		base.clear();
		bool ok=1;
		for(int i=n-1;i>=0;--i)
		{
			ll x = t[i];
			for(ll e: base) x = min(x,e^x);
			if(x==0) continue;
			if(s[i]=='0') base.pb(x);
			else
			{
				ok=0;
				break;
			}
		}
		puts(ok ? "0" : "1");
	}
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int n, a[1111111], c, g[20];
int main() {
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	g[0] = 1; c = 0;
	while(true) {
		g[c + 1] = g[c] * 3 + 1;
		if(g[++c] >= n) break;
	}
	int ret = 0;
	for(int i = c - 1; i >= 0; i--) {
		for(int j = g[i]; j < n; j++) {
			int v = a[j], w = j - g[i];
			while(w >= 0 && a[w] > v) {
				a[w + g[i]] = a[w];
				w -= g[i];
				ret++;
			}
			a[w + g[i]] = v;
		}
	}
	cout << c << endl;
	for(int i = c - 1; i >= 0; i--) {
		if(i) cout << g[i] << ' ';
		else cout << g[i] << endl;
	}
	cout << ret << endl;
	for(int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
	return 0;
}