#include <bits/stdc++.h>
using namespace std;
long long a[1000007];
vector<long long> v;
void seive() {
  for (long long i = 0; i <= 1000000; i++) a[i] = 1;
  a[0] = a[1] = 0;
  for (long long i = 2; i <= 1000; i++) {
    if (a[i] == 1) {
      v.push_back(i);
      for (long long j = 2 * i; j <= 1000000; j += i) a[j] = 0;
    }
  }
  for (long long i = 321; i <= 1000000; i++) {
    if (a[i] == 1) v.push_back(i);
  }
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    string t;
    cin >> t;
    long long r = 0;
    char c1[100000], c2[100000];
    for (long long i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        c1[r] = s[i];
        c2[r] = t[i];
        r++;
      }
    }
    if (r != 2)
      cout << "NO\n";
    else {
      if (c1[0] != c1[1] || c2[1] != c2[0])
        cout << "NO\n";
      else
        cout << "YES\n";
    }
  }
  return 0;
}
