#include <bits/stdc++.h>
using namespace std;
void swap(string &a, string &b, long long int i, long long int j) {
  char temp = a[i];
  a[i] = b[j];
  b[j] = temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string a;
    cin >> a;
    string b;
    cin >> b;
    vector<long long int> diff;
    for (long long int i = 0; i < n; i++)
      if (a[i] != b[i]) diff.push_back(i);
    if (diff.size() == 0) {
      cout << "Yes" << '\n';
      continue;
    }
    if (diff.size() == 2) {
      if (a[diff[0]] == a[diff[1]] && b[diff[0]] == b[diff[1]])
        cout << "Yes" << '\n';
      else
        cout << "No" << '\n';
      continue;
    }
    cout << "No" << '\n';
  }
  return 0;
}
