#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, i, j, g, i1, i2, d;
    cin >> n;
    string s1, s2, s3;
    cin >> s1 >> s2;
    j = 0;
    g = 0;
    for (i = 0; i < n; i++) {
      if (s1[i] != s2[i]) {
        s3[g] = s1[i];
        g++;
        s3[g] = s2[i];
        g++;
        j++;
        if (j > 2) {
          cout << "NO" << endl;
          break;
        }
      } else {
        continue;
      }
    }
    if (j == 1) {
      if (s3[0] == s3[1]) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else if (j == 2) {
      if (s3[0] == s3[2] && s3[1] == s3[3]) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
  }
}
