#include <bits/stdc++.h>
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(std::cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug &operator<<(const c &) {
    return *this;
  }
};
using namespace std;
int k;
int n;
char s[10005], t[10005];
int main(void) {
  cin >> k;
  while (k--) {
    cin >> n >> s >> t;
    queue<pair<int, int>> qq;
    for (int i = 0; i < n; ++i) {
      if (s[i] != t[i]) {
        for (int j = i + 1; j < n; ++j) {
          if (s[i] == s[j]) {
            qq.push(make_pair(j, i));
            swap(s[j], t[i]);
            break;
          } else if (s[i] == t[j]) {
            qq.push(make_pair(j, j));
            qq.push(make_pair(j, i));
            swap(s[j], t[j]);
            swap(s[j], t[i]);
            break;
          }
        }
      }
    }
    bool fl = false;
    for (int i = 0; i < n; ++i)
      if (s[i] != t[i]) fl = true;
    cout << (fl ? "No" : "Yes") << endl;
    if (!fl) {
      cout << qq.size() << endl;
      while (!qq.empty()) {
        cout << qq.front().first + 1 << ' ' << qq.front().second + 1 << endl;
        qq.pop();
      }
    }
  };
  ;
}
