#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P) {
  in >> P.first >> P.second;
  return in;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P) {
  out << "(" << P.first << ", " << P.second << ")";
  return out;
}
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
template <class T>
istream &operator>>(istream &in, deque<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const deque<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
int n, m, q, k, v[55];
vector<int> w;
vector<pair<int, int> > p;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    string second, p;
    cin >> n;
    cin >> second;
    cin >> p;
    vector<pair<int, int> > swaps;
    for (int j = 0; j < n; j++) {
      if (second[j] == p[j]) continue;
      int a = (second[j] - 'a'), b = (p[j] - 'a');
      for (int h = j + 1; h < n; h++)
        if (second[h] == second[j]) {
          swaps.push_back({h, j});
          swap(second[h], p[j]);
          break;
        }
      if (second[j] == p[j]) continue;
      for (int h = j + 1; h < n; h++)
        if (p[h] == p[j]) {
          swaps.push_back({j, h});
          swap(second[j], p[h]);
          break;
        }
      if (second[j] == p[j]) continue;
      int pa = -1, push_back = -1;
      for (int h = j + 1; h < n; h++) {
        if (second[h] == p[j]) push_back = h;
        if (p[h] == second[j]) pa = h;
      }
      if (pa != -1) {
        swap(second[pa], p[pa]);
        swap(second[pa], p[j]);
        swaps.push_back({pa, pa});
        swaps.push_back({pa, j});
      } else if (push_back != -1) {
        swap(second[push_back], p[push_back]);
        swap(second[j], p[push_back]);
        swaps.push_back({push_back, push_back});
        swaps.push_back({j, push_back});
      }
    }
    if (second == p) {
      cout << "Yes\n";
      cout << (int)(swaps).size() << "\n";
      for (auto w : swaps) cout << w.first + 1 << " " << w.second + 1 << "\n";
    } else
      cout << "No\n";
  }
}
