    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    int main(){
        int t;
        cin>>t;
        while(t--){
            ll n;
            cin>>n;
            string a,b;
            cin>>a>>b;
            ll c=0;
            ll one=0;
            ll zero=0;
            for(ll i=0;i<n;i++){
                if(a[i]=='1'){
                    one=one+1;
                }
                if(a[i]=='0'){
                    zero+=1;
                }
                if((a[i]==b[i])!=(a[i+1]==b[i+1])&&(one-zero)!=0){
                c=1;
                }
            }
            if(c>0){
                cout<<"NO"<<"\n";
            }
            if(c==0){
                cout<<"YES"<<"\n";
            }
        }
    }