#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define maxN 100000





int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	{
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	}
// #endif
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        string a,b;
        cin>>a>>b;
        if(a==b){
            cout<< "YES"<< endl;
            continue;
        }
        ll one=0,zero=0;
        set<ll> s;
        for(ll i=0;i<n;i++){
            if(a[i]=='0'){
                zero++;
            }else{
                one++;
            }
            if(one==zero){
                s.insert(i);
            }
        }
        if(s.size()==0){
            cout<< "NO"<<endl;
        }else{
            bool flag=true,f_1=true;
            for(ll i=n-1;i>=0;i--){
                if(flag){
                    if(a[i]!=b[i]){
                        if(s.find(i)==s.end()){
                            f_1=false;
                            break;
                        }
                        flag=false;
                    }
                }else{
                    if(a[i]==b[i]){
                        if(s.find(i)==s.end()){
                            f_1=false;
                            break;
                        }
                        flag=true;
                    }
                }
            }
            if(f_1){
                cout<< "YES"<<endl;
            }else{
                cout<< "NO"<<endl;
            }
        }
    }
	return 0;

}