#include<iostream>
using namespace std;
const int N=1e5+7;
void solve()
{
    string s1,s2;
    int n;
    cin>>n;
    cin>>s1>>s2;
    s1+='0';
    s2+='0';
    int flag=1;
    int num=0,num2=0,num3=0;
    for(int i=0;i<s1.size();i++)
    {

        if(s1[i]==s2[i])
        {
            if(num!=0)
                flag=0;
            if(i&&s1[i-1]!=s2[i-1])
                if(num2*2!=i)
                flag=0;
        }
        else
        {
            num+=s1[i]-s2[i];
        }
        num2+=s1[i]-'0';
    }

    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
signed main()
{
    int zs;
    cin>>zs;while(zs--)
    solve();

}
