#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, cnt = 0, flag = 1, x, y;
    cin >> n;
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        cnt++;
        (cnt == 1) ? x = i : y = i;
      }
    }
    if (cnt != 0 && cnt != 2) flag = 0;
    if (a[x] != a[y] || b[x] != b[y]) flag = 0;
    (flag == 0) ? cout << "NO" : cout << "YES";
    cout << '\n';
  }
  return 0;
}
