#include <bits/stdc++.h>
using namespace std;
long long n;
string s, t;
void input() {
  cin >> n;
  cin >> s;
  cin >> t;
}
void solve() {
  long long cnt = 0;
  long long x[100005];
  for (int i = 0; i < 100006; i++) {
    x[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      x[cnt] = i;
      cnt++;
    }
  }
  if (cnt == 2) {
    if (s[x[0]] == s[x[1]] && t[x[0]] == t[x[1]]) {
      cout << "YES";
    } else
      cout << "NO";
  } else
    cout << "NO";
  cout << endl;
}
signed main() {
  long long q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    input();
    solve();
  }
  return 0;
}
