#include <bits/stdc++.h>
using namespace std;
#define ll long long
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif
void solve() {
int n;
string s,p;
cin >> n >> s >> p;
if(n==1){
cout << (s != p ? "NO" : "YES" ) << endl;
return;
}
int p_one = count(p.begin(),p.end(),'1');
int p_zero = count(p.begin(),p.end(),'0');
if(p_zero== n && p_one == n){
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;while (t--)
solve();
return 0;
}