#include <bits/stdc++.h>
using namespace std;
string a, b;
struct node {
  int x, y;
};
vector<node> ans;
void rua() {
  ans.clear();
  int n;
  scanf("%d", &n);
  cin >> a >> b;
  for (int i = 0; i < n; i++)
    if (a[i] != b[i])
      for (int j = i + 1; j < n; j++) {
        if (a[i] == a[j]) {
          swap(a[j], b[i]);
          ans.push_back({j, i});
          break;
        }
        if (a[i] == b[j]) {
          swap(a[j], b[j]);
          ans.push_back({j, j});
          swap(a[j], b[i]);
          ans.push_back({j, i});
          break;
        }
      }
  if (a != b) {
    printf("NO\n");
    return;
  }
  printf("YES\n%d\n", (int)ans.size());
  for (auto i : ans) printf("%d %d\n", i.x + 1, i.y + 1);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) rua();
  return 0;
}
