#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, j, i;
  string s, t;
  cin >> n >> s >> t;
  vector<pair<long long int, long long int> > res;
  for (i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      for (j = i + 1; j < n; j++) {
        if (s[j] == s[i]) {
          res.push_back({j + 1, i + 1});
          swap(s[j], t[i]);
          break;
        }
        if (t[j] == s[i]) {
          res.push_back({j + 1, j + 1});
          swap(s[j], t[j]);
          res.push_back({j + 1, i + 1});
          swap(t[i], s[j]);
          break;
        }
      }
    }
  }
  if (s == t) {
    cout << "YES"
         << "\n";
    cout << res.size() << "\n";
    for (auto x : res) {
      cout << x.first << " " << x.second << "\n";
    }
  } else {
    cout << "NO"
         << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
