#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define eb emplace_back
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define here cout<<"HERE !!!"<<endl;
#define sz(v) (ll)v.size()
#define vi vector<ll>
#define print(v) for (auto it : v) cout << it << " "; cout << endl;
#define all(v) v.begin(), v.end()
#define i128 __int128
#define read(v) for(auto &it:v) cin>>it;
#define Faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
const long double pi = acos(-1.0l);
const ll inf = 4e18;
const int mod = 998244353, mx = 1e5 + 100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll my_rand(ll l, ll r)
{
return uniform_int_distribution<ll>(l, r)(rng);
}
//rotate(v.begin(), v.begin() + d, v.end());
//order_of_key(k): number of element less than k
//find_by_order(k): k-th element in set start from 0
void ravana(ll idx)
{
ll n; cin >> n;
string s, t; cin >> s >> t;
if (s == t)
{
cout << "YES" << endl;
return;
}
for (ll i = 0; i + 1 < n; i++)
{
if (t[i] == '0' and t[i + 1] == '1')
{
s[i] = '0';
s[i + 1] = '1';
}
else if (t[i] == '1' and t[i + 1] == '0')
{
s[i] = '1';
s[i + 1] = '0';
}
else
{
if (s[i] == t[i] and s[i + 1] == t[i + 1])
{
continue;
}
if (t[i] == '1')
{
s[i] = '1';
s[i + 1] = '0';
}
else
{
s[i] = '0';
s[i + 1] = '1';
}
if (i + 2 < n)
{
if (t[i + 1] == '0')
{
s[i + 1] = '0';
s[i + 2] = '1';
}
else
{
s[i + 1] = '1';
s[i + 2] = '0';
}
i++;
}
else
{
//here;
cout << "NO" << endl;
return;
}
}
//cout << s << " " << t << endl;
}
//cout << s << endl;
if (s == t)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
signed main()
{
auto begin = std::chrono::high_resolution_clock::now();
Faster;
ll t = 1;
cin >> t;
for (ll i = 1; i <= t; ++i)
{
ravana(i);
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}