#include <bits/stdc++.h>
const long long md = 167772161;
inline long long fmul(long long x, long long y, const long long P) {
  return (x * y) % P;
}
inline long long fpw(long long x, long long y, const long long modol) {
  if (x == modol - 1) return y & 1 ? modol - 1 : 1;
  long long res = 1;
  while (y) {
    if (y & 1) res = fmul(res, x, modol);
    x = fmul(x, x, modol);
    y >>= 1;
  }
  return res % modol;
}
long long exgcd(long long& x, long long& y, long long a, long long b) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long res = exgcd(y, x, b, a % b);
  y -= x * (a / b);
  return res;
}
inline long long ad(long long x, long long y, const long long md) {
  return x + y >= md ? x + y - md : x + y;
}
inline long long sub(long long x, long long y, const long long md) {
  return x < y ? md + x - y : x - y;
}
inline long long inv(long long o, const long long modol) {
  long long x, y;
  exgcd(x, y, o, modol);
  x = (x % modol + modol) % md;
  return x;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
long long mmax(long long x, long long y) { return x > y ? x : y; }
long long mmin(long long x, long long y) { return x < y ? x : y; }
const int N = 60;
char s[N], t[N];
int n;
std::vector<std::pair<int, int> > ans;
int main() {
  int T;
  scanf("%d", &T);
  int i, j;
  while (T--) {
    ans.clear();
    scanf("%d", &n);
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    bool ck = 1;
    for (i = 1; i <= n; ++i)
      if (s[i] != t[i]) {
        bool flg = 0;
        for (j = i + 1; j <= n; ++j)
          if (s[i] == s[j]) {
            ans.push_back(std::make_pair(j, i));
            std::swap(s[j], t[i]);
            flg = 1;
            break;
          }
        if (!flg)
          for (j = i + 1; j <= n; ++j)
            if (s[i] == t[j]) {
              ans.push_back(std::make_pair(j, j));
              std::swap(s[j], t[j]);
              ans.push_back(std::make_pair(j, i));
              std::swap(s[j], t[i]);
              flg = 1;
              break;
            }
        if (!flg) ck = 0;
      }
    if (ck) {
      printf("Yes\n");
      printf("%d\n", (int)ans.size());
      std::vector<std::pair<int, int> >::iterator it;
      for (it = ans.begin(); it != ans.end(); ++it)
        printf("%d %d\n", it->first, it->second);
    } else
      printf("No\n");
  }
}
