#include <bits/stdc++.h>
using namespace std;
long long n;
string s, t;
void solve() {
  map<int, int> m;
  for (long long i = 0; i < (n); ++i) {
    m[s[i]]++;
    m[t[i]]++;
  }
  for (auto i : m)
    if (i.second % 2 == 1) {
      cout << "No\n";
      return;
    }
  vector<std::pair<int, int> > p;
  for (long long i = 0; i < (n); ++i) {
    if (s[i] == t[i]) continue;
    bool f = 0;
    for (long long j = i + 1; j < (n); ++j) {
      if (s[i] == s[j]) {
        swap(s[j], t[i]);
        p.push_back({j, i});
        f = 1;
        break;
      }
    }
    if (f) continue;
    for (long long j = i + 1; j < (n); ++j) {
      if (s[i] == t[j]) {
        swap(s[j], t[j]);
        swap(s[j], t[i]);
        p.push_back({j, j});
        p.push_back({j, i});
        f = 1;
        break;
      }
    }
  }
  cout << "Yes\n";
  cout << p.size() << "\n";
  for (auto i : p) {
    cout << i.first + 1 << ' ' << i.second + 1 << "\n";
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  cin >> test;
  while (test--) {
    cin >> n;
    cin >> s >> t;
    solve();
  }
}
