#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a;
    cin >> b;
    int cnt = 0;
    int f1 = 0, f2 = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        cnt++;
        if (cnt == 1)
          f1 = i;
        else
          f2 = i;
        if (cnt > 2) break;
      }
    }
    if (cnt > 2)
      cout << "No" << endl;
    else if (cnt == 1)
      cout << "No" << endl;
    else if (a[f1] == a[f2] && b[f2] == b[f1])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
