#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
int n;
string a, b, ta, tb;
cin >> n >> a >> b;
if(n < 2){
cout << "NO\n";
return;
}else if(n == 2 && b[0] == b[1]){
cout << "NO\n";
return;
}
ta = a, tb = b;
for(int i = 0 ; i < n ; i++){
if(a[i] != b[i] && i < n - 1){
if(b[i] == '1'){
a[i] = '1', a[i+1] = '0';
}else{
a[i] = '0', a[i+1] = '1';
}
}
}
cout << (a == b ? "YES\n" : "NO\n");
}
int main(){
ios_base::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}