#include<iostream>
#include<vector>
using namespace std;
int t;
int main(){
    cin>>t;
    while(t--){
        int n;cin>>n;
        string a,b;
        vector<int> v;
        v.push_back(-1);
        cin>>a>>b;
        int a1=0,b1=0,a0=0;
        for (int i=0;i<n;i++){
            if (a[i]=='1') a1++;
            else a0++;
            if (b[i]=='1') b1++;
            if (a1==a0) v.push_back(i);
        }
        if (a1!=b1){
            cout<<"NO"<<endl;
            continue;
        }
        if (a==b){
            cout<<"YES"<<endl;
            continue;
        }
        int vlen=v.size();
        bool ok=true;
        //for(int u:v)cout<<u;
        for (int i=0;i<vlen-1;i++){

            int now=v[i]+1;
            int nxt=v[i+1];
            bool same;
            if (a[now]==b[now]) same=true;
            else same=false;
            //(same)?cout<<"true":cout<<"false";
            for (int j=now;j<=nxt;j++){
                if (a[j]==b[j] && same==false){ ok=false; break;}
                if (a[j]!=b[j] && same==true){ ok=false; break;}
            }
        }
        for (int i=v[vlen-1]+1;i<n;i++){
            if (a[i]!=b[i]) ok=false;
        }
        if (v.size()==1 && a!=b) cout<<"NO"<<endl;
        else if (ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }
}