#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int t;
cin >> t;
while(t-->0){
int n;
string a, b;
cin >> n;
cin >> a;
cin >> b;
string aa = "",bb="";
aa += a;
bb += b;
for(int i = 0; i + 1 < n; ++i){
if(a[i] != b[i]){
if(a[i] == '1'){
a[i] = '0';
if((i + 1 < n && a[i + 1] == '0' && a[i + 1] != b[i + 1])) a[i + 1] = '1'; else
if(!(i - 1 >= 0 && a[i - 1] == '1')) a[i + 1] = '1';
}else{
a[i] = '1';
if((i + 1 < n && a[i + 1] == '1' && a[i + 1] != b[i + 1])) a[i + 1] = '0'; else
if(!(i - 1 >= 0 && a[i - 1] == '0')) a[i + 1] = '0';
}
}
}
if(a == b)cout << "YES\n"; else cout << "NO\n";
}
return 0;
}