#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 s_one = count(s.begin(),s.end(),'1');
int s_zero = count(s.begin(),s.end(),'0');
int p_one = count(p.begin(),p.end(),'1');
int p_zero = count(p.begin(),p.end(),'0');
if(s_one== n && p_zero == n){
cout << "NO" << endl;
}
else if(s_zero== n && p_one == n){
cout << "NO" << endl;
}
else cout << "YES" << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;while (t--)
solve();
return 0;
}