#include <bits/stdc++.h>
using namespace std;
const long long INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
template <typename T>
void read(T &res) {
  bool flag = false;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
  for (res = ch - 48; isdigit(ch = getchar());
       res = (res << 1) + (res << 3) + ch - 48)
    ;
  flag && (res = -res);
}
template <typename T>
void Out(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) Out(x / 10);
  putchar(x % 10 + '0');
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow_mod(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
long long fact_pow(long long n, long long p) {
  long long res = 0;
  while (n) {
    n /= p;
    res += n;
  }
  return res;
}
long long mult(long long a, long long b, long long p) {
  a %= p;
  b %= p;
  long long r = 0, v = a;
  while (b) {
    if (b & 1) {
      r += v;
      if (r > p) r -= p;
    }
    v <<= 1;
    if (v > p) v -= p;
    b >>= 1;
  }
  return r;
}
long long quick_pow(long long a, long long b, long long p) {
  long long r = 1, v = a % p;
  while (b) {
    if (b & 1) r = mult(r, v, p);
    v = mult(v, v, p);
    b >>= 1;
  }
  return r;
}
bool CH(long long a, long long n, long long x, long long t) {
  long long r = quick_pow(a, x, n);
  long long z = r;
  for (long long i = 1; i <= t; i++) {
    r = mult(r, r, n);
    if (r == 1 && z != 1 && z != n - 1) return true;
    z = r;
  }
  return r != 1;
}
bool Miller_Rabin(long long n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (!(n & 1)) return false;
  long long x = n - 1, t = 0;
  while (!(x & 1)) {
    x >>= 1;
    t++;
  }
  srand(time(NULL));
  long long o = 8;
  for (long long i = 0; i < o; i++) {
    long long a = rand() % (n - 1) + 1;
    if (CH(a, n, x, t)) return false;
  }
  return true;
}
int prime[30000010], minprime[30000010];
void euler(int n) {
  int c = 0, i, j;
  for (i = 2; i <= n; i++) {
    if (!minprime[i]) prime[++c] = i, minprime[i] = i;
    for (j = 1; j <= c && i * prime[j] <= n; j++) {
      minprime[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) break;
    }
  }
}
const int N = 2e5 + 10;
char a[N], b[N];
vector<pair<int, int>> vec;
map<char, int> haha;
int main() {
  int t;
  cin >> t;
  while (t--) {
    vec.clear();
    haha.clear();
    int n;
    cin >> n;
    cin >> a + 1 >> b + 1;
    for (int i = 1; i <= n; i++) {
      haha[a[i]]++;
      haha[b[i]]++;
    }
    int flag = 0;
    for (int i = 0; i <= 25; i++) {
      if (haha[i + 'a'] & 1) {
        flag = 1;
        cout << "No" << '\n';
        break;
      }
    }
    if (flag) continue;
    for (int i = 1; i <= n; i++) {
      if (a[i] == b[i])
        continue;
      else {
        int index = 0;
        for (int j = i + 1; j <= n; j++) {
          if (a[i] == a[j]) {
            vec.push_back(pair<int, int>(j, i));
            swap(a[j], b[i]);
            index = 1;
            break;
          }
        }
        if (!index)
          for (int j = i + 1; j <= n; j++) {
            if (a[i] == b[j]) {
              vec.push_back(pair<int, int>(i, i));
              swap(a[i], b[i]);
              vec.push_back(pair<int, int>(i, j));
              swap(a[i], b[j]);
              break;
            }
          }
      }
    }
    int len = vec.size();
    if (len >= 2 * n) {
      cout << "No" << '\n';
      continue;
    }
    cout << "Yes" << '\n';
    cout << len << '\n';
    for (int i = 0; i <= len - 1; i++) {
      cout << vec[i].first << " " << vec[i].second << '\n';
    }
  }
  return 0;
}
