/**
Author : Abdullah Al Mahdi
CF Handle: abdmahdi56
Leading University,Sylhet
Submitted on:
*/
#include <bits/stdc++.h>
#define endl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define vi vector<ll>
#define all(v) v.begin(), v.end()
#define loop(i,n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
void Bismillah() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
void solve() {
int n;
cin>>n;
string s1,s2;
cin>>s1>>s2;
if (n == 1) {
cout << (s1 == s2 ?"YES\n" :"NO\n");
return;
}
if(n>=2){
bool ok2=count(all(s2), '0') > 0 && count(all(s2), '1') > 0 ;
if(ok2) yes;
else no;
}
}
int main() {
Bismillah();
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}