#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
template <typename T>
using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T>
using que = queue<T>;
template <typename T>
using deq = deque<T>;
template <typename T>
T id(T b) {
  return b;
};
template <typename T>
void chmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chmin(T &x, T y) {
  if (x > y) x = y;
}
template <typename S, typename K>
bool contains(S s, K k) {
  return s.find(k) != s.end();
}
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
constexpr ll TEN(int n) {
  if (n == 0)
    return 1LL;
  else
    return 10LL * TEN(n - 1);
}
int main() {
  fastio();
  int k;
  cin >> k;
  for (size_t i = 0; i < size_t(k); i++) {
    int n;
    string s, t;
    cin >> n >> s >> t;
    vec<pii> ans;
    bool ok = true;
    for (size_t i = 0; i < size_t(n); i++) {
      if (s[i] != t[i]) {
        auto it = find(s.begin() + i + 1, s.end(), s[i]);
        if (it != s.end()) {
          int j = it - s.begin();
          char c = s[j];
          s[j] = t[i];
          t[i] = c;
          ans.emplace_back(j + 1, i + 1);
          continue;
        }
        it = find(t.begin() + i + 1, t.end(), s[i]);
        if (it != t.end()) {
          int j = it - t.begin();
          char c = t[i];
          t[i] = t[j];
          t[j] = c;
          ans.emplace_back(i + 1, i + 1);
          ans.emplace_back(i + 1, j + 1);
          continue;
        }
        ok = false;
      }
    }
    if (ok) {
      cout << "Yes\n";
      cout << ans.size() << '\n';
      for (auto [i, j] : ans) cout << i << " " << j << '\n';
    } else {
      cout << "No\n";
    }
  }
  return 0;
}
