// Author: Shawn Das Shachin-->(shawn_das)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define OPTIMIZE_IO ios::sync_with_stdio(false); cin.tie(nullptr);
void solve()
{
int n;
cin>>n;
string s,p;
cin>>s>>p;
if(n==1){
if(s==p)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else if(n==2){
if (s == p || p == "01" || p == "10")cout <<"YES"<<endl;
else cout << "NO"<<endl;
}
else{
bool flag=1;
for(int i=0; i<n-1; i++){
if(p[i]==p[i+1]){
if(s[i]==s[i+1]){
flag=1;
}
else{
flag=0;
}
}
}
if(flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
int main()
{
OPTIMIZE_IO;
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}