#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define PB push_back
#define vll vector<long long>
#define ll long long
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define ld long double
#define vld vector<long double>
const ll mod = 998244353;
const ll MOD = 1e9 + 7;
void solve(int tst){
int n;
string s, t;
cin >> n;
cin >> s >> t;
vector<bool> dp(n + 10, false);
dp[0] = true;
s = '-' + s;
t = '-' + t;
for (int i = 1; i <= n; i++){
if (i - 1 > 0 && t[i - 1] != t[i]) dp[i] = true;
if (s[i] == t[i]) dp[i] = max(dp[i - 1], dp[i]);
}
cout << (dp[n] ? "YES\n" : "NO\n");
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// pre();
int tc = 1;
cin >> tc;
for (int i = 1; i <= tc; i++){
solve(i);
}
return 0;
}