#include <bits/stdc++.h>
using namespace std;
const long long mod = 10000007;
const long long INF = LLONG_MAX;
const int N = 1001000;
void solve () {
int n;
string s, s1;
cin >> n >> s1 >> s;
if (n == 1) {
if (s[0] != s1[0]) {
cout << "NO";
return;
}
}
if (s[n - 2] == '1' && s[n - 1] == '1') {
if (s1[n - 2] != '1' || s1[n - 1] != '1') {
cout << "NO";
return;
}
} else if (s[n - 2] == '0' && s[n - 1] == '0') {
if (s1[n - 2] != '0' || s1[n - 1] != '0') {
cout << "NO";
return;
}
}
cout << "YES";
}
int main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long t;
cin >> t;
while (t--) {
solve();
cout << "\n";
}
return 0;
}