#include <bits/stdc++.h>
int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};
int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int MOD = 1e9 + 7, N = 3e5 + 5, oo = 1e9;
const double pi = acos(-1);
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    map<char, int> f;
    for (int i = 0; i < n; i++) {
      f[s[i]]++;
      f[t[i]]++;
    }
    vector<pair<int, int>> vec;
    bool ok = true;
    for (char c = 'a'; c <= 'z'; c++) ok &= (f[c] % 2 == 0);
    if (!ok)
      cout << "No" << '\n';
    else {
      for (int i = 0; i < n; i++) {
        if (s[i] == t[i]) continue;
        bool swapped = false;
        for (int j = i + 1; j < n; j++) {
          if (s[j] == s[i]) {
            vec.push_back({j + 1, i + 1});
            swap(t[i], s[j]);
            swapped = true;
            break;
          }
        }
        if (!swapped) {
          for (int j = i + 1; j < n; j++) {
            if (s[i] == t[j]) {
              vec.push_back({j + 1, j + 1});
              swap(s[j], t[j]);
              vec.push_back({j + 1, i + 1});
              swap(t[i], s[j]);
              break;
            }
          }
        }
      }
      cout << "Yes\n" << (int)(vec).size() << '\n';
      for (auto it : vec) cout << it.first << ' ' << it.second << '\n';
    }
  }
  return 0;
}
