#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, ans = 1, c = 0;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<pair<int, int> > res;
    int q = 0;
    while (q < 2 * n && a != b) {
      for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) {
          int cng = 0;
          for (int j = 0; j < n; j++) {
            if (j == i) continue;
            if (a[j] == a[i] && b[j] != a[i]) {
              cng = 1;
              char ch = b[j];
              b[j] = a[i];
              a[i] = ch;
              res.push_back(make_pair(i, j));
              q++;
              break;
            }
          }
          if (!cng) {
            char ch = b[i];
            b[i] = a[i];
            a[i] = ch;
            res.push_back(make_pair(i, i));
            q++;
          }
        }
      }
    }
    if (a == b) {
      cout << "Yes" << '\n';
      cout << res.size() << '\n';
      for (auto x : res) {
        cout << x.first + 1 << " " << x.second + 1 << '\n';
      }
    } else
      cout << "No" << '\n';
  }
  return 0;
}
