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