#include <bits/stdc++.h>
using namespace std;
int findC(string s, char c, int start, int n) {
  for (long long i = start; i <= n; i++) {
    if (s[i] == c) return i;
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  cin >> k;
  while (k--) {
    vector<pair<int, int>> v;
    map<char, int> mp;
    int n, go = 1;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (long long i = 0; i < n; i++) {
      mp[s[i]]++;
      mp[t[i]]++;
    }
    for (auto it = mp.begin(); it != mp.end(); it++) {
      if (it->second % 2 != 0) {
        cout << "No" << '\n';
        go = 0;
        break;
      }
    }
    if (go) {
      cout << "Yes" << '\n';
      for (long long i = 0; i < n; i++) {
        if (s[i] != t[i]) {
          int sec = 0;
          int it = findC(t, s[i], i + 1, n);
          if (it == -1) {
            it = findC(s, s[i], i + 1, n);
            sec = 1;
          }
          if (sec) {
            v.push_back({it + 1, i + 1});
            swap(t[i], s[it]);
          } else {
            v.push_back({i + 2, it + 1});
            swap(s[i + 1], t[it]);
            v.push_back({i + 2, i + 1});
            swap(s[i + 1], t[i]);
          }
        }
      }
      cout << v.size() << '\n';
      for (long long i = 0; i < v.size(); i++) {
        cout << v[i].first << " " << v[i].second << '\n';
      }
    }
  }
  return 0;
}
