#include <bits/stdc++.h>
using namespace std;
#define ll long long
#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'
int n;
string s, t;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt;
cin >> tt;
while (tt--)
{
cin >> n >> s >> t;
if (s == t)
{
cout << "YES\n";
continue;
}
if (count(all(t), '1') - count(all(s), '1') ==0 or count(all(t), '1') - count(all(s), '1') == 1)
{
cout << "YES\n";
continue;
}else
{
cout << "NO\n";
}
}
return 0;
}