#include <bits/stdc++.h>
using namespace std;
void read() {
  freopen("pudge.in", "r", stdin);
  freopen("pudge.out", "w", stdout);
}
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void pudge() {
  int n, cnt = 0;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  bool f = true;
  char x1 = ' ', x2 = ' ', y1 = ' ', y2 = ' ';
  for (int i = 0; i < n; i++) {
    if (s1[i] != s2[i]) {
      cnt++;
      if (cnt > 2) {
        cout << "NO\n";
        return;
      }
      if (f) {
        x1 = s1[i];
        y1 = s2[i];
        f = false;
      } else {
        x2 = s1[i];
        y2 = s2[i];
      }
    }
  }
  if (x1 == x2 && y1 == y2)
    cout << "YES\n";
  else
    cout << "NO\n";
}
signed main() {
  faster();
  int q;
  cin >> q;
  for (int k = 0; k < q; k++) pudge();
  return 0;
}
