#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 922337203685477;
const long long mininf = -922337203685477;
const long long nax = 0;
long long q, n;
string s, t;
void solve() {
  cin >> n;
  cin >> s >> t;
  vector<long long> idx;
  for (long long i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      idx.push_back(i);
    }
  }
  if (idx.size() != 2) {
    cout << "NO" << '\n';
  } else {
    long long cura = idx[0];
    long long curb = idx[1];
    if (s[cura] == s[curb] && t[cura] == t[curb]) {
      cout << "YES" << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> q;
  while (q--) {
    solve();
  }
}
