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