#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');
if(cnt == n or cnt == 0) {
cout << "NO\n";
}
else cout << "YES\n";
};
Test_Case();
}
return 0;
}