#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  if (s == t) {
    cout << "Yes\n";
    return;
  }
  vector<pair<int, int>> ans;
  for (int i = 0; i < n; i++) {
    if (s[i] == t[i]) continue;
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        swap(t[i], s[j]);
        ans.emplace_back(j, i);
        break;
      } else if (s[i] == t[j]) {
        swap(s[j], t[j]);
        swap(t[i], s[j]);
        ans.emplace_back(j, j);
        ans.emplace_back(j, i);
        break;
      }
    }
    if (s[i] != t[i]) {
      cout << "No\n";
      return;
    }
  }
  cout << "Yes\n";
  cout << ans.size() << '\n';
  for (auto p : ans) {
    cout << p.first + 1 << " " << p.second + 1 << '\n';
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) solve();
  return 0;
}
