#include <bits/stdc++.h>
char s[60];
char t[60];
bool func1(int n) {
  int d[26];
  for (int i = 0; i < 26; i++) d[i] = 0;
  for (int i = 0; i < n; i++) {
    d[s[i] - 'a']++;
    d[t[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (d[i] % 2) return false;
  }
  return true;
}
void worker() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  scanf("%s", t);
  if (!func1(n)) {
    puts("No");
    return;
  }
  std::vector<std::pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        std::swap(s[j], t[i]);
        v.push_back({j + 1, i + 1});
        break;
      } else if (s[i] == t[j]) {
        std::swap(s[j], t[j]);
        v.push_back({j + 1, j + 1});
        std::swap(s[j], t[i]);
        v.push_back({j + 1, i + 1});
        break;
      }
    }
  }
  printf("Yes\n%d\n", v.size());
  for (auto k : v) printf("%d %d\n", k.first, k.second);
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) worker();
}
