#include <bits/stdc++.h>
#define FASTIO cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
int n, cnt[300100][2];
string a, b;

int main() {
	FASTIO;
	int q;
	cin >> q;
	while (q--) {
		a.clear();
		b.clear();
		cin >> n >> a >> b;
		for (int i = 1; i <= n; i++) {
			cnt[i][0] = cnt[i - 1][0] + (a[i - 1] == '0');
			cnt[i][1] = cnt[i - 1][1] + (a[i - 1] == '1');
		}
		int changes = 0;
		bool ok = true;
		for (int i = n; i >= 1; i--) {
			if ((a[i - 1] ^ changes) != b[i - 1]) {
				if (cnt[i][0] != cnt[i][1]) {
					ok = false;
					break;
				} else 
					changes ^= 1;
			}
		}
		
		if (ok)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}
