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