#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  for (int z = 0; z < q; z++) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        for (int j = i + 1; j < n; j++) {
          if (s[i] == s[j]) {
            v.push_back(make_pair(j + 1, i + 1));
            swap(s[j], t[i]);
            break;
          }
          if (s[i] == t[j]) {
            v.push_back(make_pair(j + 1, j + 1));
            swap(s[j], t[j]);
            v.push_back(make_pair(j + 1, i + 1));
            swap(s[j], t[i]);
            break;
          }
        }
      }
    }
    if (s == t) {
      cout << "Yes" << endl;
      cout << v.size() << endl;
      for (auto p : v) {
        cout << p.first << " " << p.second << endl;
      }
    } else {
      cout << "No" << endl;
    }
  }
}
