#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
 
#define fr(i, a, b) for (int i=a; i<(b); i++)
#define FOR(i, a) for (int i=0; i<(a); i++)
#define bck(i,a,b) for (int i = (b)-1; i >= a; i--)
#define BACK(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
  
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
bool comp(vector<ll>&a, vector<ll>&b){
	return a[1] < b[1] ;
}

void solve(){
	int n ; cin>> n; 
	string s,t; cin>> s>>t ;
	int one = 0 , zero=  0 ;
	vector<int>pos(n,0) ;
	int i= 0 ;
	for (auto x : s ) {(x=='0' ? zero ++ : one ++ ); if (zero==one) pos[i] =1 ; i+=1 ;}
	bool flag = 0 ;
	for (int i= n-1 ;i>=0; i-=1) {
		if (pos[i]==1) {
			if (flag) {
				if (s[i] == t[i]) flag = 0 ;
			}
			else {
				if (s[i] != t[i]) flag =1 ;
			}
		}
		else {
			if (flag) {
				if (s[i] == t[i]) {
					cout << "NO"<<endl;
					return ;
				}
			}
			else {
				if (s[i] != t[i]) {
					cout << "NO"<<endl;
					return ; 
				}
			}
		}
	}
	cout << "YES" <<endl; 
}
 
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t ;
	 // t=1 ;
	 cin>>t ;
	 // int i=1 ;
	while (t--){	
		solve();
		 // cout <<endl; 
		// i+=1 ; 
	}
}