#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  map<char, int> m;
  for (auto it : s) m[it]++;
  for (auto it : t) m[it]++;
  for (auto it : m) {
    if (it.second % 2) {
      cout << "No\n";
      return;
    }
  }
  vector<pair<int, int> > ans;
  while (s != t) {
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        int k = -1;
        for (int j = i + 1; j < n; j++) {
          if (s[i] == t[j]) {
            k = j;
            break;
          }
        }
        if (k != -1) {
          ans.push_back({n, k + 1});
          swap(s[n - 1], t[k]);
          ans.push_back({n, i + 1});
          swap(s[n - 1], t[i]);
          break;
        } else {
          for (int j = i + 1; j < n; j++) {
            if (s[i] == s[j]) {
              k = j;
              break;
            }
          }
          ans.push_back({k + 1, i + 1});
          swap(s[k], t[i]);
          break;
        }
      }
    }
  }
  if (ans.size() == 0) {
    ans.push_back({1, 1});
    ans.push_back({1, 1});
  }
  cout << "Yes\n";
  cout << ans.size() << "\n";
  for (auto it : ans) cout << it.first << " " << it.second << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
  return 0;
}
