#include<bits/stdc++.h>
using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif


    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string a;
        string b;

        cin>>a>>b;

        int count0 = 0;
        int count1 = 0;
        for(int i = 0;i<a.length();i++)
        {
            if(a[i] == '0')
                count0++;
            else
                count1++;
        }


        int f = 0;
        int flag = 1;
        for(int i = n-1;i>=0;i--)
        {

            

            if(f == 0)
            {
                //cout << i << " ";
                if(a[i]!=b[i] && count1 == count0)
                {
                    //cout << i << "\n";
                    f = (f + 1)%2;
                    if(a[i] == '1')
                        count0--;
                    else
                        count1--;
                    continue;
                    
                } 
                else if(a[i]!=b[i])
                {
                    flag = 0;
                    break;
                }
                if(a[i] == '0')
                    count0--;
                else
                    count1--;
            }
            else
            {
                //cout << i << " ";
                if(a[i]==b[i] && count1 == count0)
                {
                    //cout << i << "\n";
                    f = (f + 1)%2;
                    if(a[i] == '0')
                        count0--;
                    else
                        count1--;
                    continue;
                    
                } 
                else if(a[i]==b[i])
                {
                    flag = 0;
                    break;
                }
                if(a[i] == '0')
                    count1--;
                else
                    count0--;
            }
            
        }
        if(flag) cout << "YES\n";
        else cout << "NO\n"; 




        
    }
    

    









    return 0;
}