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