#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

void solve() {
	int n;
	cin >> n;
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	if (s1.back() == s2.back() && s2.back() == s3.back()) {
		char c = s1.back();
		char x = '1' + '0' - c;
		for (int i = 0; i < 2 * n; ++i) {
			cout << x;
		}
		cout << c << "\n";
		return;
	}
	int cnt0 = 0, cnt1 = 0;
	char c = '0';
	vector<string> strs = {s1, s2, s3};
	for (int i = 0; i < 3; ++i) {
		if (strs[i].back() == '0') {
			++cnt0;
		} else {
			++cnt1;
		}
	}
	if (cnt1 > cnt0) {
		c = '1';
	}
	char x = '0' + '1' - c;
	for (int i = 0; i < n; ++i) {
		cout << c;
	}
	for (int i = 0; i < n; ++i) {
		cout << x;
	}
	cout << c << "\n";
}

int main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;

	for (int i = 0; i < t; ++i) {
		solve();
	}

}

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

struct UnionFind {
    vector<int> par;
    vector<int> siz;
    UnionFind(int N) : par(N),siz(N) {
        for (int i=0; i<N; i++) {
            par[i]=i,siz[i]=1;
        }
    }
    int root(int x) {
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        if (rx==ry) return;
        par[rx]=ry;
        siz[ry]+=siz[rx];
    }
    bool same(int x,int y) {
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
    int size (int x) {
        return siz[root(x)];
    }
};

int main() {
   int N,M;
   cin >> N >> M;
   vector<vector<pair<int,int>>> G(N);
   UnionFind tree(N);
   int A[N];
   memset(A,0,sizeof(A));
   for (int i=0; i<M; i++) {
       int u,v,c;
       cin >> u >> v >> c;
       if (tree.same(u-1,v-1)) continue;
       tree.unite(u-1,v-1);
       G[u-1].push_back({v-1,c});
       G[v-1].push_back({u-1,c});
   }
   queue<tuple<int,int,int>> q;
   for (int i=0; i<N; i++) {
       if (G[i].size()==1) {
           q.push(make_tuple(i,G[i][0].first,G[i][0].second));//position,position,distance
           A[i]=1;
           break;
       }
   }
   while (!q.empty()) {
       tuple<int,int,int> p=q.front();
       q.pop();
       int a=get<0>(p),b=get<1>(p),d=get<2>(p);
       if (d==A[a]) {
           if (d==1) A[b]=2;
           else A[b]=1;
       }
       else A[b]=d;
       for (auto x:G[b]) {
           int a=x.first;
           if (A[a]==0) {
               q.push(make_tuple(b,x.first,x.second));
           }
       }
   }
   for (int i=0; i<N; i++) cout << A[i] << endl;
}