#include <bits/stdc++.h>
int main() {
  int k;
  std::cin >> k;
  while (k--) {
    int n;
    std::cin >> n;
    std::string s1, s2;
    std::cin >> s1 >> s2;
    std::vector<std::pair<int, int> > ans;
    std::vector<int> alpha(26, 0);
    for (int i = 0; i < n; ++i) {
      alpha[s1[i] - 'a']++;
      alpha[s2[i] - 'a']++;
    }
    bool ok = true;
    for (int &d : alpha) {
      if (d & 1) {
        ok = false;
      }
    }
    if (!ok) {
      std::cout << "No" << std::endl;
    }
    if (ok) {
      for (int i = 0; i < n; ++i) {
        if (s1[i] != s2[i]) {
          bool f = false;
          for (int j = i + 1; j < n; ++j) {
            if (s1[j] == s1[i]) {
              ans.push_back({j + 1, i + 1});
              f = true;
              std::swap(s1[j], s2[i]);
              break;
            }
          }
          if (!f) {
            for (int j = i + 1; j < n; ++j) {
              if (s2[j] == s1[i]) {
                ans.push_back({j + 1, j + 1});
                std::swap(s1[j], s2[j]);
                ans.push_back({j + 1, i + 1});
                std::swap(s1[j], s2[i]);
                break;
              }
            }
          }
        }
      }
      std::cout << "Yes" << std::endl;
      std::cout << ans.size() << std::endl;
      for (auto &p : ans) {
        std::cout << p.first << ' ' << p.second << std::endl;
      }
    }
  }
  return 0;
}
