#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using llu = unsigned long long;
using ld = long double;

#define CEIL(x, y) (ll)ceil((ld)(x) / (ld)(y))

#define dbgPR(ds) cout << ds.first << ' ' << ds.second
#define dbgLST(ds) for(auto it : ds) cout << it << ' '
#define dbgMP(ds) for(auto it : ds) cout << it.first << ' ' << it.second << '\n'
#define print_case cout << "Case " << tc << ": "

const double PI = acos(-1.0), g = 9.80665;
const int unseen = -1;
const ll inf = 1e18 + 505, ninf = - 1e18 - 505;
const int MOD = 1000000007;

void solve(void)
{
    int n;
    string a, b;
    cin >> n >> a >> b;
    vector<vector<int>> freq;
    freq.assign(n, vector<int> (2, 0));

    int cnt0 = 0, cnt1 = 0;
    for(int i = 0; i < a.size(); i++) {
        if(a[i] - '0') cnt1++;
        else cnt0++;
        freq[i][0] = cnt0;
        freq[i][1] = cnt1;
    } 

    bool state = 0;    
    for(int i = a.size() - 1; i >= 0; i--) {
        if(state == 0) {
            if(a[i] != b[i]) {
                if(freq[i][0] != freq[i][1]) {
                    cout << "NO\n";
                    return;
                }
                state = 1;
            }
        }
        else {
            if(a[i] == b[i]) {
                if(freq[i][0] != freq[i][1]) {
                    cout << "NO\n";
                    return;
                }
                state = 0;
            }   
        }
    }

    cout << "YES\n";
}

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 

    int testcase = 1;
    cin >> testcase;
    for(int tc = 1; tc <= testcase; tc++) {
        // print_case;
        solve();
    }  
    return 0;   
}