#include<bits/stdc++.h>
using namespace std;
#define ll long long
#ifndef ONLINE_JUDGE
#define dbg(x) cout << #x << ":- " << x << "\n"
#else
#define dbg(x)
#endif
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(),x.rend()
#define MOD 1000000007
//-----------------------------------------------------------------------------//
void print(vector<ll>arr){for(int i=0;i<arr.size();i++){cout<<arr[i]<<" ";}
cout<<endl;}
void print(map<ll,ll>mpp){for(auto x:mpp){cout<<x.first<<"-->"<<x.second<<"\n";}
cout<<endl;}
void print(set<ll>s){for(auto x:s){cout<<x<<" ";}cout<<endl;}
//------------------------------------------------------------------------------//
/*
s,t
s=t
s-> choose any consecutive indices and change them to 10, 01
10101001
is tha lst index bounded
1. we can never make the count of 1 zero in the s.(except if it already had 0 1's)
2.
*/
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
ll n;
cin>>n;
string s,t;
cin>>s>>t;
ll cnt1=count(all(t),'0');
ll cnt2=count(all(t),'1');
if(cnt1==0||cnt2==0){
if(s==t)cout<<"YES\n";
else cout<<"NO\n";
}
else{
cout<<"YES\n";
}
}
return 0;
}