#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <map>
#include <sstream>
#include <stack>
#include <bitset>
#include <random>
using ll = long long;
using namespace std;
constexpr int nm = 32;
void solve() {
int n;
string s, p;
cin >> n >> s >> p;
if (s == p) {
cout << "YES\n";
return;
}
if (p == string(n, '0') || p == string(n, '1')) {
cout << "NO\n";
return;
}
cout << "YES\n";
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) solve();
}