#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define bug(x) cerr << #x << " = " << x << endl
#define rem(v,x) (v).erase(remove((v).begin(), (v).end(), (x)), (v).end())
#define leftrotate(v,k) rotate((v).begin(), (v).begin() + ((k) % (v).size()), (v).end())
#define rightrotate(v,k) rotate((v).begin(), (v).end() - ((k) % (v).size()), (v).end())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define lz(x) __builtin_clz(x)
#define lzll(x) __builtin_clzll(x)
#define tz(x) __builtin_ctz(x)
#define tzll(x) __builtin_ctzll(x)
void fast() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
template <typename T>
void print(const vector<T>& vec) { for (const auto& val : vec) cout << val << " "; cout << endl; }
void solve() {
int n; cin >> n;
string a, b;
cin >> a >> b;
if(n == 1 && a != b){
cout << "NO" << endl;
return;
}
if(a == b){
cout << "YES" << endl;
return;
}
vector<int> fa(2), fb(2);
for(int i = 0; i < n; i++){
if(a[i] == '1') fa[1]++;
if(a[i] == '0') fa[0]++;
if(b[i] == '1') fb[1]++;
if(b[i] == '0') fb[0]++;
}
if(fa[0] == fb[0]){
cout << "YES" << endl;
return;
}
if(fb[1] == 0 || fb[1] == n){
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
}
int main() {
fast();
int t = 1;
cin >> t;
while (t--) solve();
}