#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      if (s1[i] != s2[i]) v.push_back(i);
    }
    if (v.size() == 0) {
      cout << "YES"
           << "\n";
    } else if ((int)v.size() != 2)
      cout << "NO"
           << "\n";
    else {
      int i = v[0];
      int j = v[1];
      if (s1[i] == s1[j] && s2[i] == s2[j])
        cout << "YES"
             << "\n";
      else
        cout << "NO"
             << "\n";
    }
  }
  return 0;
}
