#include<bits/stdc++.h>
using namespace std;
string a;
string b;
int main(){
    int T;
    cin >> T;
    while(T--){
        a.clear();
        b.clear();
        int n;
        scanf("%d\n",&n);
        getline(cin,a);
        getline(cin,b);
        int cnt_0=0;
        int cnt_1=0;
        int flag_A=a[0]-'0'^b[0]-'0';
        int flag=0;
        for(int i=0;i<a.size();i++){
            if(a[i]=='1')cnt_1++;
            else cnt_0++;
            if(cnt_0!=cnt_1){
                if(flag_A!=a[i]-'0'^b[i]-'0'){flag=1;break;}
            }else {
                if(flag_A!=a[i]-'0'^b[i]-'0'){flag=1;break;}
                if(i+1<a.size())flag_A=a[i+1]-'0'^b[i+1]-'0';
                else flag_A=0;
            }
        }
        if(flag||flag_A==1)cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}