#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> a;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll t;
  cin >> t;
  while (t--) {
    a.clear();
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    if (s == t) {
      ans = 1;
    }
    if (s != t) {
      for (ll i = 0; i < n; i++) {
        if (s[i] != t[i]) {
          a.push_back(i);
        }
      }
      if (a.size() != 2) {
        ans = 0;
      }
      if (a.size() == 2) {
        swap(s[a[0]], t[a[1]]);
        if (s == t) {
          ans = 1;
        }
      }
    }
    cout << (ans ? "Yes" : "No") << "\n";
  }
}
