#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 300010;

int n;
char a[N], b[N];

int main()
{
    int T;
    cin>>T;
    while(T --)
    {
        cin>>n;
        for(int i = 1; i <= n; i ++) cin>>a[i];
        for(int i = 1; i <= n; i ++) cin>>b[i];
        int cnt1 = 0, cnt2 = 0;
        for(int i = 1; i <= n; i ++)
        {
            if(a[i] == '1') cnt1 ++;
            if(b[i] == '1') cnt2 ++;
        }
        if(cnt1 != cnt2) 
        {
            cout<<"NO"<<endl;
            continue;
        }
        bool flag = true;
        cnt1 = 0, cnt2 = 0;
        bool same = false;
        for(int i = 1; i <= n; i ++)
        {
            if(a[i] != b[i] && same)
            {
                if(cnt1 != cnt2)
                {
                    flag = false;
                    break;
                }
                same = false;
            }
            if(a[i] == b[i] && !same)
            {
                if(cnt1 != cnt2)
                {
                    flag = false;
                    break;
                }
                same = true;
            }
            if(a[i] == '1') cnt1 ++;
            else cnt2 ++;
        }
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    
    return 0;
}