#include <bits/stdc++.h>
using namespace std;
int main() {
  long long k;
  cin >> k;
  while (k--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int mi[2] = {0};
    int m = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        if (m < 2) mi[m] = i;
        m++;
      }
    }
    if (m > 2 || m == 1) {
      cout << "NO\n";
    } else {
      if (m == 0)
        cout << "YES\n";
      else if (a[mi[0]] == a[mi[1]] && b[mi[0]] == b[mi[1]])
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
  return 0;
}
