/*
    Username : moondancer
    Name : Moon Dancer
*/


#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        string s, t;
        cin >> s >> t;
        int zero = 0, one = 0;
        for (int i = 0; i < n; ++i) {
            if(s[i] == '0') {
                zero++;
            }
            else {
                one++;
            }
        }
        bool invers = 0;
        bool f = 1;
        for (int i = n - 1; i >= 0; --i) {
            if(invers == 0) {
                if(s[i] != t[i]) {
                    if(zero == one) {
                        invers ^= 1;
                    }
                    else {
                        f = 0;
                        break;
                    }
                }
            }
            else {
                if(s[i] == t[i]) {
                    if(zero == one) {
                        invers ^= 1;
                    }
                    else {
                        f = 0;
                        break;
                    }
                }
            }
            if(invers == 0) {
                if(s[i] == '0') {
                    zero--;
                }
                else {
                    one--;
                }
            }
            else {
                if(s[i] == '0') {
                    one--;
                }
                else {
                    zero--;
                }
            }
        }
        if(f) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
    }
    return 0;
}