#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  vector<int> chk(26);
  for (int i = 0; i < n; i++) {
    chk[s[i] - 'a']++;
    chk[t[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (chk[i] % 2) {
      cout << "No\n";
      return;
    }
  }
  vector<pair<int, int>> vp;
  for (int i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      for (int j = i + 1; j < n; j++) {
        if (s[j] == t[i]) {
          swap(s[j], t[j]);
          vp.emplace_back(j, j);
          break;
        }
      }
      for (int j = i + 1; j < n; j++) {
        if (t[j] == t[i]) {
          swap(s[i], t[j]);
          vp.emplace_back(i, j);
          break;
        }
      }
    }
  }
  cout << "Yes\n";
  cout << vp.size() << "\n";
  for (const auto &p : vp) {
    cout << p.first + 1 << ' ' << p.second + 1 << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
}
