#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n, i, j;
  cin >> t;
  while (t--) {
    cin >> n;
    string a, b;
    cin.ignore();
    getline(cin, a);
    getline(cin, b);
    vector<int> ai;
    vector<int> bi;
    bool ans = true;
    for (int i = 0; i < n; i++) {
      if (a[i] == b[i]) continue;
      char ch = a[i];
      bool chk = false;
      for (int j = i + 1; j < n; j++) {
        if (a[j] == ch) {
          swap(b[i], a[j]);
          ai.push_back(j);
          bi.push_back(i);
          chk = true;
          break;
        } else if (b[j] == ch) {
          swap(a[i + 1], b[j]);
          swap(a[i + 1], b[i]);
          ai.push_back(i + 1);
          ai.push_back(i + 1);
          bi.push_back(j);
          bi.push_back(i);
          chk = true;
          break;
        }
      }
      if (!chk) {
        ans = false;
        break;
      }
    }
    if (ans) {
      cout << "Yes\n";
      cout << ai.size() << "\n";
      for (int i = 0; i < ai.size(); ++i) {
        cout << ai[i] + 1 << " " << bi[i] + 1 << "\n";
      }
    } else
      cout << "No\n";
  }
  return 0;
}
