#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define rev_str(str) reverse(str.begin(),str.end());
#define print(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i =a ;i<b;i++)
#define per(i,b,a) for(ll i=b;i>=a;i--)
bool sortByValue(const pair<int,int>& a,const pair<int,int>& b){
return a.second > b.second;
}
void solve(){
ll n;
cin >> n;
string a, b;
cin >> a >> b;
string x, y;
x = b, y = a;
for (int i = 0; i < n - 1; i++){
// first string
if (a[i] < a[i + 1]){
if (a[i] > x[i]){
swap(a[i], x[i]);
}
}
else{
swap(a[i], x[i]);
}
//second string
if (b[i] < b[i + 1]){
if (b[i] > y[i]){
swap(b[i], y[i]);
}
}
else{
swap(b[i], y[i]);
}
}
//cout << a << ' ' << b << endl;
if ((is_sorted(a.begin(), a.end()) && a[0] <= a[n-1]) || (is_sorted(b.begin(), b.end()) && b[0] <= b[n-1])){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
}
int main(){
fast;
ll t=1;cin>>t;
while(t--){
solve();
}
return 0;
}