#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<long long> v;
    for (long long i = 0; i < n; i++) {
      if (s[i] != t[i]) v.push_back(i);
    }
    if (v.size() != 2)
      cout << "NO" << endl;
    else {
      if (s[v[0]] == s[v[1]] && t[v[0]] == t[v[1]])
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
}
