#include <bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define ld long double
#define f(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl '\n'
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 998244353
#define ANS cout<<ans<<endl
#define minHeap priority_queue<ll,vector<ll>,greater<ll>>
#define maxHeap priority_queue<ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
ll gcd(ll a, ll b) {return __gcd(a,b);}
ll lcm(ll a, ll b) {return a* (b/gcd(a,b));}
//const int m=1e9+7;
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = (res * a);
a = (a * a);
b >>= 1;
}
return res;
}
bool subseq(string a,string b)
{
ll x=a.size();
ll y=b.size();
if(x>y)return 0;
ll i = 0, j = 0;
while (i < x && j < y ){
if (a[i] == b[j])i++;
j++;
}
return i==x;
}
bool iscomposite(ll n)
{
for(int i=2;i<=sqrt(n);i++)
{
if(n%i==0)
{
return 1;
}
}
return 0;
}
long long toDec(const string& binary) {
long long decimal = 0;
long long base = 1;
for (int i = binary.size() - 1; i >= 0; --i) {
if (binary[i] == '1') {
decimal += base;
}
base *= 2LL;
}
return decimal;
}
string toBin(long long n) {
string temp;
if (n == 0) return "0";
while (n > 0) {
temp = (n % 2LL == 0 ? "0" : "1") + temp;
n = n / 2LL;
}
return temp;
}
int calculateSum(const vector<int>& v) {
int total = 0;
for (int x : v) {
total += x;
}
return total;
}
bool check(char c1, char c2){
if (c1 == '(' && c2 == ')') return true;
return false;
}
ll moduexp(ll a,ll b){
ll ret=1;
while(b){
if(b%2)ret=(ret*a)%MOD;
a=(a*a)%MOD;
b/=2;
}
return ret;
}
ll moduinv(ll x) {
return moduexp(x,MOD-2);
}
const int mx=6005;
ll parent[mx];
ll find(ll u) {
if(parent[u]!=u)parent[u]=find(parent[u]);
return parent[u];
}
bool uni(ll u, ll v) {
ll pu=find(u);
ll pv=find(v);
if (pu==pv)return 0;
parent[pu]=pv;
return 1;
}
bool sortbyCond(const pair<int, int>& a, const pair<int, int>& b) {
if (a.first != b.first)
return a.first < b.first;
else
return a.second > b.second;
}
bool is_substring(string a, string b) {
return b.find(a) != string::npos;
}
const int N=1e6+123;
bitset<N> isprime;
vector<int>prime;
void primegen(){
//n+=100;
isprime[2]=1;prime.push_back(2);
for(int i=3;i<=N;i+=2)isprime[i]=1;
for(int i=3;i<sqrt(N);i+=2)
{
if(isprime[i]==1)
{
for(int j=i*i;j<=N;j+=(i+i))isprime[j]=0;
}
}
for(int i=3;i<=N;i+=2)
{
if(isprime[i])
{
prime.push_back(i);
}
}
}
long long phi(ll n){
ll ret = n;
for( auto p : prime){
if(1LL*p*p > n || n == 0) break;
if(n % p == 0){
ret /= p;
ret *= (p-1);
while(n % p == 0) n /= p;
}
}
if(n > 1){
ret /= n;
ret *= (n-1);
}
return ret;
}
/*
min heap with priority queue:
priority_queue<ll,vector<ll>,greater<ll>> minHeap;
*/
//const int N = 200005;
vector<int> adj[N];
vector<bool> visited(N,0);
bool isCycleComponent;
int nodes=0, edges=0;
void dfs(int u) {
visited[u] = true;
nodes++;
edges += adj[u].size();
for (int v : adj[u]) {
if (!visited[v]) {
dfs(v);
}
}
}
int countCycleComponents(int n) {
int cycleCount = 0;
for (int i = 1; i <= n; i++) {
if (!visited[i]) {
nodes = 0;
edges = 0;
dfs(i);
edges /= 2;
if (edges == nodes && nodes > 2) {
cycleCount++;
}
}
}
return cycleCount;
}
ll my_lower_bound(const vector<ll>& v, ll X) {
ll n = v.size();
ll low = 0;
ll high = n;
ll ans = n;
while (low < high) {
ll mid = low + (high - low) / 2;
if (v[mid] >= X) {
ans = mid;
high = mid;
} else {
low = mid + 1;
}
}
return ans;
}
ll my_upper_bound(const vector<ll>& v, ll X) {
ll n = v.size();
ll low = 0;
ll high = n;
ll ans = n;
while (low < high) {
ll mid = low + (high - low) / 2;
if (v[mid] > X) {
ans = mid;
high = mid;
} else {
low = mid + 1;
}
}
return ans;
}
ll maxSubarraySum(vector<ll> &arr){
ll res = arr[0];
ll maxEnding = arr[0];
for (ll i = 1; i < arr.size(); i++) {
maxEnding = max(arr[i], maxEnding + arr[i]);
res = max(res, maxEnding);
}
return res;
}
bool isPowerOfTwo(ll n) {
if (n <= 0) {
return false;
}
return (n & (n - 1)) == 0;
}
ll dist[N];
void diameter(ll n, ll par){
for(auto u:adj[n]){
if(u!=par){
dist[u]=dist[n]+1;
diameter(u,n);
}
}
}
ll subtree_size[N];
void subtree_size_calculator(ll child,ll parent){
subtree_size[child]=1;
for(auto u:adj[child]){
if(u==parent)
continue;
subtree_size_calculator(u,child);
subtree_size[child]+=subtree_size[u];
}
}
//sorting a vector of pair where first value will be in increasing order and second value will be in decreasing order
bool custom_sort(const pair<pair<ll, ll>, ll>& a, const pair<pair<ll, ll>, ll>& b){
if (a.first.first != b.first.first) {
return a.first.first < b.first.first;
}
return a.first.second > b.first.second;
}
const int fc=3e5+10;
int fact[fc];
void factorial(){
fact[0]=1;
for(ll i=1;i<=fc;i++){
fact[i]=((fact[i-1]%MOD)*(i%MOD))%MOD;
}
}
vll divisors(ll n){
vll v;
for(ll i=1;i*1LL*i<=n;i++){
if(n%i==0){
ll a=i;
ll b=n/i;
if(a==b){
v.pb(a);
continue;
}
else{
v.pb(a);
v.pb(b);
}
}
}
return v;
}
void solve(){
ll n;cin>>n;
string s;cin>>s;
string p;cin>>p;
if(n==1){
if(s==p){
cout<<"YES\n";
return;
}
else{
cout<<"NO\n";
return;
}
}
bool contain0=0;
bool contain1=0;
for(ll i=0;i<n;i++){
if(p[i]=='0')contain0=1;
else contain1=1;
}
if(contain0 and contain1){
cout<<"YES\n";
}
else{
if(s==p){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
}
int main() {
// primegen();
ll t;cin >> t;while (t--)
{
//primegen(1e6);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
solve();
}
return 0;
}