#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0) {
    long long k = power(x, y / 2);
    return (k * k) % 1000000007;
  } else {
    long long k = power(x, y / 2);
    return (x * ((k * k) % 1000000007)) % 1000000007;
  }
}
int main() {
  long long q;
  cin >> q;
  long long u = 0;
  while (q--) {
    long long n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    long long c = 0;
    long long k = 0, j = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        c++;
        j = k;
        k = i;
      }
    }
    if (c > 2 || c == 1) {
      cout << "NO" << endl;
    } else {
      if (c == 2) {
        if (s[k] == s[j] && t[k] == t[j]) {
          cout << "YES" << endl;
        } else {
          cout << "NO" << endl;
        }
      }
    }
  }
}
