#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    int n, a;
    cin >> n;
    string s, t;
    cin >> s;
    cin >> t;
    int cnt = 0, flag = 1;
    int arr[2];
    int j = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        cnt++;
        if (cnt > 2) {
          flag = 0;
          goto h;
        }
        arr[j] = i;
        j++;
      }
    }
    if (cnt == 1) {
      flag = 0;
    } else if (s[arr[0]] == s[arr[1]] and t[arr[0]] == t[arr[1]]) {
      flag = 1;
    } else {
      flag = 0;
    }
  h:;
    if (flag) {
      cout << "Yes";
    } else {
      cout << "No";
    }
    cout << endl;
  }
  return 0;
}
