#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, t, a, bc, d, g, n, m, flag, p, q, l, r, x, y, z;
  cin >> t;
  while (t--) {
    cin >> n;
    flag = 0;
    string a, b;
    cin >> a >> b;
    unordered_map<char, int> mp;
    for (i = 0; i < n; i++) {
      mp[a[i]]++;
      mp[b[i]]++;
    }
    for (auto it : mp) {
      if (it.second % 2 != 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 1)
      cout << "No" << endl;
    else {
      cout << "Yes" << endl;
      vector<pair<int, int>> v;
      for (i = 0; i < n; i++) {
        if (a[i] != b[i]) {
          for (j = i + 1; j < n; j++) {
            if (a[j] == a[i]) {
              a[j] = b[i];
              v.push_back(make_pair(j, i));
              break;
            } else if (b[j] == a[i]) {
              b[j] = b[i];
              v.push_back(make_pair(i, i));
              v.push_back(make_pair(i, j));
              break;
            }
          }
        }
      }
      cout << v.size() << endl;
      for (i = 0; i < v.size(); i++)
        cout << v[i].first + 1 << " " << v[i].second + 1 << endl;
    }
  }
  return 0;
}
