#include <bits/stdc++.h>
using namespace std;
int n, k;
void solve() {
  string l = "", s, t;
  cin >> n;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      k++;
      l += s[i];
      l += t[i];
    }
  }
  if (k != 2)
    cout << "NO" << endl;
  else {
    if (l.substr(0, 2) == l.substr(2, 2))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  l = "";
  k = 0;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
