#include <bits/stdc++.h>
using namespace std;
int inf = 0x3f3f3f3f;
const int maxn = 10010;
char s[maxn], t[maxn];
int n;
bool check(int &l, int &r) {
  l = -1, r = -1;
  for (int i = 0; i < n; ++i) {
    if (s[i] != t[i]) {
      if (l == -1)
        l = i;
      else if (r == -1)
        r = i;
      else
        return false;
    }
  }
  if (r == -1) return false;
  return true;
}
int main() {
  int k;
  cin >> k;
  while (k--) {
    cin >> n;
    scanf("%s%s", s, t);
    int l, r;
    if (!check(l, r))
      puts("No");
    else {
      if (s[l] == s[r] && t[l] == t[r])
        puts("Yes");
      else
        puts("No");
    }
  }
}
