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

# define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define len(s) int(s.size())
#define na "NO"
#define ha "YES"
#define pb push_back
#define rev(a) reverse(all(a))
#define s second
#define f first
#define read(arr, n)  for (int i = 0; i < n; i++)  cin >> arr[i];
#define read2(arr, n , m)  for (int i = 0; i < n; i++) for(int j=0; j<m; j++) cin >> arr[i][j];
#define  ll long long
#define mem(a,val) memset(a,val,sizeof(a)).
#define vi vector<int>


void IO()
{
	fast;
}


ll binary_exponention(ll a, ll b) {
	if (b == 0)
		return 1;
	ll res = binary_exponention(a, b / 2);
	if (b % 2)
		return res * res * a;
	return res * res ;
}
string invert(string a) {
	string ans = "";
	for (char c : a) {
		if (c == '1') ans.pb('0');
		else ans.pb('1');
	}
	return ans;
}
void solve()
{
	int n; cin >> n;
	string s; cin >> s;
	string b ; cin >> b;
	vector<int> ind;
	ind.pb(-1);
	int ones = 0;

	for (int i = 0; i < n; i++) {
		ones += s[i] == '1';
		if (i % 2)
			if (ones  == (i + 1) / 2) ind.pb(i);
	}
	for (int i = 1; i < len(ind); i++) {

		int t = ind[i];
		int p = ind[i - 1];
		auto sub = s.substr(p + 1, t - p);
		if (!(sub == b.substr(p + 1, t - p) || invert(sub) == b.substr(p + 1, t - p)) ) {
			cout << na << endl;
			return;
		}

	}

	int non_change_able_suffix = ind.back() + 1;
	if (s.substr(non_change_able_suffix , n - non_change_able_suffix) != b.substr(non_change_able_suffix , n - non_change_able_suffix)) {
		cout << na << endl;
		return;
	}

	cout << ha << endl ;

}

int main()
{
	IO();
	int t; cin >> t; while (t--)
		solve();

#ifndef ONLINE_JUDGE
	cerr  << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
	return 0;

}
