#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int LINF = 0x3f3f3f3f3f3f3f;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int k;
  cin >> k;
  string second, t;
  int freq[130];
  while (k--) {
    memset(freq, 0, sizeof(freq));
    int n;
    vector<pair<int, int> > ans;
    cin >> n;
    cin >> second >> t;
    for (int i = 0; i < n; i++) {
      freq[second[i]]++;
      freq[t[i]]++;
    }
    for (int i = 0; i < 130; i++) {
      if (freq[i] % 2) {
        cout << "No"
             << "\n";
        goto fim;
      }
    }
    for (int i = 0; i < n; i++) {
      if (second[i] == t[i]) continue;
      int opa = 0;
      for (int j = i + 1; j < n; j++)
        if (second[j] == second[i]) {
          swap(second[j], t[i]);
          ans.push_back({j, i});
          opa = 1;
          break;
        }
      if (opa) continue;
      for (int j = i + 1; j < n; j++) {
        if (second[i] == t[j]) {
          swap(second[j], t[j]);
          ans.push_back({j, j});
          swap(t[i], second[j]);
          ans.push_back({j, i});
          break;
        }
      }
    }
    cout << "Yes"
         << "\n";
    cout << ans.size() << "\n";
    for (auto a : ans) cout << a.first + 1 << " " << a.second + 1 << endl;
  fim:
    continue;
  }
}
