/**********************************************
* AUTHOR : Subhrangshu Pandey
* INSTITUTION : HIT, Kolkata
**********************************************/
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod ((long long)(1e9+7))
#define endl "\n"
#define all(x) (x).begin(), (x).end()
//smaller always visited and larger never
#define rep(i, begin, end) for(ll i = begin; i < end; ++i)
#define rev(i, begin, end) for(ll i = begin; i >= end; --i)
#define timetaken cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n"
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    
	ll t; cin>>t; while(t--){
		ll n;
		cin>>n;
		string s1, s2;
		cin>>s1>>s2;

		bool isposs = true;
		bool allsm = true, allsw = true;
		ll cnt0 = 0, cnt1 = 0;
		rep(i, 0, n){
			if(s1[i] == s2[i])
				allsw = false;
			else allsm = false;
			// if(!(allsm || allsw)){
			// 	isposs = false;
			// 	break;
			// }
			(s1[i] == '1') ? cnt1++ : cnt0++;
			// cout<<i<<" allsw: "<<allsw<<" allsm: "<<allsm<<" cnt0: "<<cnt0<<" cnt1: "<<cnt1<<endl;
			if(cnt1 == cnt0 && (allsw || allsm)){
				allsm = true;
				allsw = true;
				cnt0 = 0, cnt1 = 0;

			// cout<<i<<" in allsw: "<<allsw<<" allsm: "<<allsm<<" cnt0: "<<cnt0<<" cnt1: "<<cnt1<<endl;
			}
			else if(i == n-1 && !allsm){
				isposs = false;
			}
		}
		cout<<(isposs ? "YES\n" : "NO\n");
	}

	timetaken;
	return 0;
}