#include <bits/stdc++.h>
using namespace std;
long long int n, i, val, t;
string c, d;
vector<long long> v;
void do_king() {
  cin >> t;
  while (t--) {
    v.clear();
    cin >> n;
    int cnt = 0;
    val = 0;
    cin >> c >> d;
    for (i = 0; i < n; ++i) {
      if (c[i] != d[i]) {
        v.push_back(i);
      }
    }
    if (v.size() > 2) {
      cout << "NO" << endl;
    } else if (v.size() == 2) {
      swap(c[v[0]], d[v[1]]);
      if (c == d) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else {
      cout << "NO" << endl;
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  do_king();
}
