#include <bits/stdc++.h>
using namespace std;
const int MX = 10010896;
const int lmt = 3164;
const int N = 10000001;
int flag[MX >> 6];
int main() {
  int k;
  cin >> k;
  string s, t;
  for (int _ = 0; _ < k; _++) {
    int n, x, y, c = 0;
    cin >> n >> s >> t;
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        if (c == 0) {
          c++;
          x = i;
        } else if (c == 1) {
          c++;
          y = i;
        } else {
          c++;
          break;
        }
      }
    }
    if (c == 2) {
      if (s[x] == s[y] && t[x] == t[y]) {
        cout << "YES"
             << "\n";
      } else {
        cout << "NO"
             << "\n";
      }
    } else {
      cout << "NO"
           << "\n";
    }
  }
  return 0;
}
