#include <bits/stdc++.h> // All praise is due to Allah alone, and peace and blessings be
using namespace std; // upon him, after whom there is no other Prophet.
int32_t main() {
cin.tie(0)->sync_with_stdio(false);
int32_t Case = 1; cin >> Case;
for (int T = 1; T <= Case; T++) {
int n; cin >> n;
string s, p; cin >> s >> p;
if(s == p) {
cout << "YES\n"; continue;
}
function<void()> Test_Case = [&]() {
if(n & 1) {
cout << "NO\n"; return;
}
int cnt = count(p.begin(), p.end(), '0');
int cnt1 = n - cnt;
if(cnt == 0 or cnt1 == 0) {
cout << "NO\n"; return;
}
for(int i = 0; i < n - 1; i++) {
if(s[i] != p[i]) {
if(s[i] == '0') {
s[i] = '1', s[i + 1] = '0';
}
else {
s[i] = '0', s[i + 1] = '1';
}
}
}
if(s.back() == p.back()) cout << "YES\n";
else cout << "NO\n";
};
Test_Case();
}
return 0;
}