#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;
int f11 = 0, f00 = 0, f10 = 0;
f(i, n - 1)
{
if (s[i] == '1' and s[i + 1] == '1')
f11 = 1;
if (s[i] == '0' and s[i + 1] == '0')
f00 = 1;
if (s[i] != s[i + 1])
f10 = 1;
}
if (s == t)
{
cout << "YES\n";
continue;
}
if (n == 1)
{
cout << "NO\n";
continue;
}
sort(all(t));
if (t[0] == t.back())
cout << "NO\n";
else
cout << "YES\n";
end:;
}
return 0;
}