#include <bits/stdc++.h>
using namespace std;
bool check(int st, int en, int inc, string s, string &p) {
for (int i = st; min(st, en) <= i && i <= max(st, en); i += inc) {
if (s[i] != p[i]) {
s[i] = p[i];
s[i + inc] = p[i] ^ '0' ^ '1';
}
}
// cout << st << " " << en << " " << (s == p) << endl;
return (s == p);
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef SUBLIME
freopen("inputf.in", "r", stdin);
freopen("outputf.out", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int tt;
cin >> tt;
while (tt--) {
int n;
string s, p;
cin >> n >> s >> p;
if (n == 1) {
if (s != p) cout << "NO\n";
else cout << "YES\n";
continue;
}
cout << ((check(0, n - 2, 1, s, p) || check(n - 1, 1, -1, s, p)) ? "YES" : "NO") << "\n";
}
return 0;
}