#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        string a;
        cin >> a;

        string b;
        cin >> b;

        bool okay = true;

        bool last = false;
        int zeros = 0, ones = 0;

        for (auto x: b) {
            if (x == '0')
                zeros++;
            else
                ones++;
        }

        for (int i = n - 1; i >= 0; i--) {
            if (!last) {
                if (a[i] != b[i]) {
                    if (ones != zeros) {
                        okay = false;
                        break;
                    }
                    last = true;
                }
            } else {
                if (a[i] == b[i]) {
                    if (ones != zeros) {
                        okay = false;
                        break;
                    }
                    last=false;
                }
            }
            if (b[i] == '0')
                zeros--;
            else
                ones--;
        }

        cout << (okay ? "YES\n" : "NO\n");
    }
}


