#include <bits/stdc++.h>
using namespace std;
int k, n;
string s, t;
int main() {
  cin >> k;
  while (k--) {
    cin >> n;
    cin >> s;
    cin >> t;
    int pos1;
    int pos2;
    int c = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        c++;
        if (c == 1)
          pos1 = i;
        else
          pos2 = i;
      }
    }
    if (c == 0)
      cout << "Yes" << endl;
    else if (c != 2)
      cout << "No" << endl;
    else if (s[pos1] == s[pos2] && t[pos1] == t[pos2])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
