#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string s, p;
cin >> s >> p;
for (int i = 0; i < n - 1; i++)
{
if (s[i] == p[i])
continue;
s[i] = (s[i] ^ '0' ^ '1');
if (s[i] == '0')
s[i + 1] = '1';
else
s[i + 1] = '0';
}
if (s == p)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}