#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize "trapv"
#define ll long long

void solve() {
    int n; string a,b; cin>>n>>a>>b;
    int f0=0,f1=0;
    vector<bool> marked(n);
    for (int i=0;i<n;i++) {
    	if (a[i]=='0')
    		f0++;
    	else
    		f1++;
    	if (f0==f1) {
    		//cout<<i<<endl;
    		bool allsame = true;
    		bool toggled = true;
    		for (int j=i;j>=0 && !marked[j];j--) {
    			if (a[j]!=b[j]) 
    				allsame = false;
    			if (a[j]==b[j])
    				toggled = false;
    		}
    		if (allsame || toggled) 
    			marked[i] = true;
    		else {
    			cout<<"NO\n";
    			return;
    		}
    	}
    }
    bool same = true;	//or marked
    for (int i=n-1;i>=0 && !marked[i];i--) {
    	if (a[i]!=b[i]) {
    		same = false;
    		break;
    	}
    }
    if (same) cout<<"YES\n";
    else cout<<"NO\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t; cin>>t;
    while (t--) 
        solve();
    return 0;
}