#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
int Q; cin >> Q;
while (Q--)[&] {
int n; cin >> n;
string s, t;
cin >> s >> t;
// int l = 0, r = n-1;
// while (l < n && s[l] == t[l]) l++;
// while (r >= 0 && s[r] == t[r]) r--;
// if (r == -1) {
// cout << "YES\n";
// return;
// }
for (int i = 0; i < n-1; i++) {
if (s[i] != t[i]) {
if (t[i] == '0') s[i] = '0', s[i + 1] = '1';
else s[i] = '1', s[i + 1] = '0';
}
}
for (int i = n-1; i > 0; --i) {
if (s[i] != t[i]) {
if (t[i] == '0') s[i] = '0', s[i - 1] = '1';
else s[i] = '1', s[i - 1] = '0';
}
}
cout << (s == t ? "YES" : "NO") << "\n";
}();
}