#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define     REP(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int main()
{
    int test = 1;
     cin >> test;
    while (test--)
    {
        
         int i,j,n,f2=1,O=0,Z=0;
         cin>>n;
          string s1,s2;
         cin>>s1>>s2;
         int o[n+2],z[n+3];
         for(i=0;i<n;i++)
         {
             if(s1[i]=='1') O++;
             else Z++;
             o[i]=O;
             z[i]=Z;
         }
         int f=1;
         for(i=n-1;i>=0;)
         {
             if(s1[i]==s2[i])
             {
                   if(f==0&&o[i]!=z[i])
                    {
                        f2=0; break;
                    }
                    while(i>=0&&s1[i]==s2[i]) i--;
                    if(s1[i]!=s2[i]) f=1;
             }else
             {
                if(f==1&&o[i]!=z[i])
                    {
                        f2=0; break;
                    }
                    while(i>=0&&s1[i]!=s2[i]) i--;
                    if(s1[i]==s2[i]) f=0;
             }
         }
      if(f2==0) cout<<"NO"<<endl  ;
      else cout<<"YES"<<endl;
    }

    return 0;
}