#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n;
char s[maxn];
char t[maxn];
multimap<char, int> a, b;
int ans;
int x[maxn << 1];
int y[maxn << 1];
void Print(multimap<char, int> tmp) {
  for (char ch = 'a'; ch <= 'z'; ++ch) {
    if (!tmp.count(ch)) continue;
    printf("%c:", ch);
    for (auto it = tmp.equal_range(ch).first; it != tmp.equal_range(ch).second;
         ++it)
      printf("%d ", (*it).second);
    printf("\n");
  }
  printf("\n");
}
bool Work1(int i) {
  char ch = s[i];
  int j = n + 1;
  for (auto it = a.equal_range(ch).first; it != a.equal_range(ch).second; ++it)
    if ((*it).second > i) j = min(j, (*it).second);
  if (j == n + 1) return false;
  swap(s[j], t[i]);
  x[++ans] = j;
  y[ans] = i;
  for (auto it = a.equal_range(ch).first; it != a.equal_range(ch).second; ++it)
    if ((*it).second == j) {
      a.erase(it);
      break;
    }
  a.insert(make_pair(s[j], j));
  return true;
}
void Work2(int i) {
  char ch = s[i];
  int j = n + 1;
  for (auto it = b.equal_range(ch).first; it != b.equal_range(ch).second; ++it)
    if ((*it).second > i) j = min(j, (*it).second);
  for (auto it = a.equal_range(s[j]).first; it != a.equal_range(s[j]).second;
       ++it)
    if ((*it).second == j) {
      a.erase(it);
      break;
    }
  for (auto it = b.equal_range(t[j]).first; it != b.equal_range(t[j]).second;
       ++it)
    if ((*it).second == j) {
      b.erase(it);
      break;
    }
  swap(s[j], t[j]);
  x[++ans] = j;
  y[ans] = j;
  swap(s[j], t[i]);
  x[++ans] = j;
  y[ans] = i;
  a.insert(make_pair(s[j], j));
  b.insert(make_pair(t[j], j));
}
void Solve() {
  a.clear();
  b.clear();
  for (int i = 1; i <= n; ++i) a.insert(make_pair(s[i], i));
  for (int i = 1; i <= n; ++i) b.insert(make_pair(t[i], i));
  for (char i = 'a'; i <= 'z'; ++i)
    if ((a.count(i) + b.count(i)) & 1) return puts("No"), void(0);
  ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (s[i] == t[i]) continue;
    if (!Work1(i)) Work2(i);
  }
  puts("YES");
  printf("%d\n", ans);
  for (int i = 1; i <= ans; ++i) printf("%d %d\n", x[i], y[i]);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    scanf("%s%s", s + 1, t + 1);
    Solve();
  }
  return 0;
}
