#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s = "";
    string t = "";
    cin >> s >> t;
    unordered_map<char, int> mp;
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        mp[s[i]]++;
        mp[t[i]]++;
      }
    }
    int flag = 1;
    for (auto x : mp) {
      if (x.second % 2 != 0) {
        flag = 0;
        break;
      }
    }
    vector<pair<int, int>> moves;
    if (flag == 0)
      cout << "No"
           << "\n";
    else {
      for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] != t[i]) {
          auto it = find(s.begin() + i + 1, s.end(), s[i]);
          if (it != s.end()) {
            moves.push_back({it - s.begin() + 1, i + 1});
            swap(t[i], s[it - s.begin()]);
          } else {
            auto it = find(t.begin() + i + 1, t.end(), s[i]);
            moves.push_back({(it - t.begin() + 1), (it - t.begin() + 1)});
            swap(s[it - t.begin()], t[it - t.begin()]);
            moves.push_back({it - t.begin() + 1, i + 1});
            swap(s[it - t.begin()], t[i]);
          }
        }
      }
      cout << "Yes"
           << "\n";
      cout << moves.size() << "\n";
      for (auto x : moves) cout << x.first << " " << x.second << "\n";
    }
  }
}
