#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <queue>
#include <deque>
#include <cstring>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <unordered_map>
using namespace std;
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define bg begin
#define rbg rbegin
#define ed end
#define endl '\n'
#define dbg(x) cout << #x << "===" << x << endl
typedef double db;
typedef long long ll;
typedef unsigned long long ull;

const int N = 3e5;
int a[N], b[N], vis[N];

int gcd(int a, int b) {
	return !b ? a : gcd(b, a % b);
}

ll qpow(ll a, ll b, ll mod) {
	ll ans = 1;
	while (b) {
		if (b & 1)	ans = (ans * a) % mod;
		a = (a * a) % mod, b >>= 1;
	}
	return ans % mod;
}

int main() {

	//freopen("D:\\测试用\\in.txt", "r", stdin);
	//freopen("D:\\测试用\\out.txt", "w+", stdout);
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		int sum0, sum1;
		sum0 = sum1 = 0;
		rep(i, 1, n) {
			scanf("%1d", &a[i]);
			vis[i] = 0;
			if (a[i])	sum1++;
			else sum0++;
		}
		rep(i, 1, n)	scanf("%1d", &b[i]);
		per(i, n, 1) {
			if (sum0 == sum1) vis[i] = 1;
			if (a[i])	sum1--;
			else sum0--;
		}
		int f = 1;
		int sum = 0;
		per(i, n, 1) {
			if (sum & 1)	a[i] ^= 1;
			if (a[i] != b[i]) {
				if (vis[i]) {
					a[i] ^= 1;
					sum++;
				}
				else f = 0;
			}
		}
		if (f)	cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}