#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,one = 0,zero = 0;
        string a,b;
        cin>>n;
        cin>>a>>b;
        vector<ll>vec;
        ll flag = 0;
        for(ll i=0;i<n;i++)
        {
            if(a[i]=='0')
                zero++;
            else
                one++;
            
            if(one == zero)
                vec.push_back(1);
            else
                vec.push_back(0);
        }
        for(ll i=n-1;i>-1;i--)
        {
            if(i == n-1 && (a[i]!=b[i]))
            {
                if(vec[i]==0)
                {
                    flag = 1;
                    break;
                }
            }
            else if (i<n-1)
            {
                if(a[i]==b[i] && a[i+1]!=b[i+1])
                {
                    if(vec[i]==0)
                    {
                        flag = 1;
                        break;
                    }

                }
                if(a[i]!=b[i] && a[i+1]==b[i+1])
                {
                    if(vec[i]==0)
                    {
                        flag = 1;
                        break;
                    }

                }
            }

        }
        if(flag)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
        

    }
}