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