#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        string a, b;
        cin >> a >> b;
        V<P> cnt(n+1);
        P p = {0, 0};
        rep(i, n) {
            P np = p;
            if(a[i] == '0') np.first++;
            else np.second++;
            cnt[i] = np;
            p = np;
        }
        bool ok = true;
        int inv = 0;
        for(int i = n-1; i >= 0; i--) {
            int x = a[i] - '0';
            if(inv) x ^= 1;
            if(x == b[i] - '0') continue;
            else {
                inv ^= 1;
                if(cnt[i].first != cnt[i].second) {
                    ok = false;
                    break;
                }
            }
        }
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
