#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    string diff1;
    string diff2;
    for (int i = 0; i < N; i++) {
      if (s[i] != t[i]) {
        diff1 += s[i];
        diff2 += t[i];
      }
    }
    bool ok = true;
    if (diff1.size() != 2) ok = false;
    swap(diff1[0], diff2[1]);
    if (diff1 != diff2) ok = false;
    cout << (ok ? "Yes\n" : "No\n");
  }
  return 0;
}
