#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, c = 0, i, a = -1, b = -1;
    cin >> n;
    string s1, s2, ans;
    cin >> s1;
    cin >> s2;
    for (i = 0; i < n; i++) {
      if (s1[i] != s2[i]) {
        c++;
        if (a == -1)
          a = i;
        else
          b = i;
      }
    }
    if (c == 0) {
      cout << "Yes";
      continue;
    }
    if (c == 1 || c > 2)
      ans = "No";
    else {
      if (s1[a] == s1[b] && s2[a] == s2[b])
        ans = "Yes";
      else
        ans = "No";
    }
    cout << ans << "\n";
  }
}
