#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int times, l;
string in1, in2;
bool d[300010];
int main() {
    cin >> times;
    while (times--) {
        memset(d, false, sizeof(d));
        cin >> l >> in1 >> in2;
        int c1 = 0, c2 = 0, count = 0;
        for (int i = 0; i < l; i += 2) {
            if (in1[i] - 48) c1++;
            else c2++;
            if (in1[i + 1] - 48) c1++;
            else c2++;
            if (c1 == c2) d[i + 1] = true;
        }
        bool flag = true;
        for (int i = l - 1; i >= 0; --i) {
            if ((in1[i] != in2[i] && count % 2 == 0 && !d[i]) || (in1[i] == in2[i] && count & 1 && !d[i])) {
                flag = false;
                cout << "NO\n";
                break;
            } else if ((in1[i] != in2[i] && count % 2 == 0) || (in1[i] == in2[i] && count & 1)) {
                count++;
            }
        }
        if (flag) cout << "YES\n";
    }
    return 0;
}