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

const int Maxn = 400004;

char tmp[Maxn];
int T;
int n;
string A, B, C;
int nxtA[Maxn][2], nxtB[Maxn][2], nxtC[Maxn][2];
char res[Maxn];
int rlen;

void Read(string &S, int nxt[][2])
{
	scanf("%s", tmp);
	S = tmp; S = S + S;
	nxt[S.length()][0] = nxt[S.length()][1] = S.length();
	for (int i = int(S.length()) - 1; i >= 0; i--) {
		nxt[i][0] = nxt[i + 1][0];
		nxt[i][1] = nxt[i + 1][1];
		nxt[i][S[i] - '0'] = i;
	}
}

int main()
{
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		Read(A, nxtA);
		Read(B, nxtB);
		Read(C, nxtC);
		printf("%s%s%s\n", string(n, '0').c_str(), string(n, '1').c_str(), string(1, '0').c_str());
	}
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n, sum = 0, ans=0;
  cin >> n;
  vector<ll> a(n),an(n);
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
    ans += a[i] * a[i];
  }
  ans *= (n-1);
  ll tmp = 0;
  rep(i, n) {
    sum -= a[i];
    ans -= a[i] * sum * 2;
  }
  cout << ans << endl;

  return 0;
}