#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int freqs[26] = {}, freqt[26] = {};
    int n, i, j, fl = 0;
    cin >> n;
    string second, t;
    cin >> second >> t;
    for (i = 0; i < n; i++) {
      freqs[second[i] - 97]++;
      freqt[t[i] - 97]++;
    }
    for (i = 0; i < 26; i++) {
      if ((freqs[i] + freqt[i]) % 2 != 0) {
        cout << "No\n";
        fl = 1;
        break;
      }
    }
    if (fl == 0) {
      vector<pair<int, int> > ans;
      cout << "Yes\n";
      for (i = 0; i < n; i++) {
        if (second[i] != t[i]) {
          for (j = i + 1; j < n; j++) {
            if (second[j] == second[i]) {
              ans.push_back({j + 1, i + 1});
              swap(second[j], t[i]);
              break;
            }
            if (second[i] == t[j]) {
              ans.push_back({j + 1, j + 1});
              swap(second[j], t[j]);
              ans.push_back({j + 1, i + 1});
              swap(second[j], t[i]);
              break;
            }
          }
        }
      }
      cout << ans.size();
      cout << "\n";
      for (i = 0; i < ans.size(); i++) {
        cout << ans[i].first << " " << ans[i].second;
        cout << "\n";
      }
    }
  }
  return 0;
}
