#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  bool solve(string& s, string& t) {
    int n = s.length();
    vector<int> diffs;
    for (int i = 0; i < n; ++i) {
      if (s[i] != t[i]) {
        diffs.push_back(i);
      }
    }
    if (diffs.empty()) {
      return true;
    } else if (diffs.size() == 2) {
      int a = diffs[0], b = diffs[1];
      if (s[a] == s[b] && t[b] == t[a]) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int t;
  cin >> t;
  while (t-- > 0) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    cout << (sol.solve(s, t) ? "Yes" : "No") << "\n";
  }
  return 0;
}
