#include<bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#ifdef LOCAL
#define READF freopen("in.txt","r",stdin)
#else
#define READF if(0)
#define cerr if(0) cout
#endif
#define fr first
#define sc second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chk cerr<<"masuk"<<endl
#define deb(x) cerr << #x << " = " << x <<'\n'
#define arpr(ar_,t_) 	cerr<< #ar_ << ":\n";					\
						for(int i_=0;i_<t_;i_++){				\
							if(i_==t_-1) cerr<<ar_[i_]<<'\n';	\
							else cerr<<ar_[i_]<<" "; 			\
						}
using namespace std;
const ll N = 1e5 + 5;

ll n,m,i,j;
vector<ll> flip;
bool ev;
string a,b;

int main(){
	FASTIO; READF;
	ll t;
	cin>>t;
	while(t--){
		flip.clear();
		cin>>n>>a>>b;
		ev = a[0] == b[0];
		ll ztala = 0, otala = 0, ztalb = 0, otalb = 0;
		i = 0;
		while(i < n){
			ll st = i;
			while((a[st] == b[st]) == (a[i] == b[i]) && i < n){
				a[i] == '0' ? ztala++ : otala++;
				b[i] == '0' ? ztalb++ : otalb++;
				i++;
			}
		//	deb(ztala); deb(otala);deb(ztalb); deb(otalb);
			// flip.pb(i - 1);
			if(otala != otalb || ztala != ztalb) break;
			if(i < n && otala != ztala) break;
			else{
				otala = 0;ztala = 0;
				otalb = 0;ztalb = 0;
			}
		}
		(otala == otalb && ztala == ztalb && otala == ztala) ? cout<<"YES"<<endl : cout<<"NO"<<endl;
		// arpr(flip, flip.size());
	}
}

