#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int powll(long long int x, long long int n) {
  long long int r = 1;
  while (n) {
    if (n & 1) r = r * x % mod;
    n = n / 2;
    x = x * x % mod;
  }
  return r;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int diff = 0;
    int sa[26] = {0}, ta[26] = {0};
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        diff++;
        sa[s[i] - 'a']++;
        ta[t[i] - 'a']++;
      }
    }
    if (diff == 2) {
      int i;
      for (i = 0; i < 26; i++) {
        if ((sa[i] != 0) && (sa[i] != 2)) break;
        if ((ta[i] != 0) && (ta[i] != 2)) break;
      }
      if (i == 26)
        cout << "Yes" << '\n';
      else
        cout << "No" << '\n';
    } else
      cout << "No" << '\n';
  }
  return 0;
}
