#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

void solve() {
    ll n; cin >> n;
    string s, t; cin >> s >> t;
    ll ocnt = 0; ll zcnt = 0;
    vector<ll> lines = {0}; ll last = 0;
    REP(i,n) {
        if (s[i]=='1') ocnt++;
        else zcnt++;
        if (ocnt==zcnt) {
            bool jud = true;
            ll checker = 0;
            FOR(j,last,i) {
                if (j==last) {
                    if (s[last]==t[last]) checker=0;
                    else checker=1;
                }
                else {
                    if (checker && s[j]==t[j]) jud = false;
                    else if (checker==0 && s[j]!=t[j]) jud = false;
                }
            }
            if (jud==false) {
                cout << "NO" << endl;
                return;
            }
            last = i+1;
        }
    }
    FOR(i,last,n-1) {
        if (s[i]!=t[i]) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
    return;
}

int main(){
    ll t; cin >> t;
    REP(i,t) solve();
    return 0;
}