#include <bits/stdc++.h>
using namespace std;
int const N = 200001;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    string s, t;
    scanf("%d", &n);
    cin >> s >> t;
    set<int> msA[200], msB[200];
    map<char, int> f;
    for (int i = 0; i < n; ++i) {
      msA[s[i]].insert(i);
      msB[t[i]].insert(i);
      ++f[s[i]], ++f[t[i]];
    }
    bool ok = true;
    for (char i = 'a'; i <= 'z'; ++i)
      if (f[i] & 1) {
        ok = false;
        break;
      }
    vector<pair<int, int> > an;
    if (!ok) {
      puts("NO");
      continue;
    }
    for (int i = 0; i < n; ++i) {
      if (s[i] == t[i]) continue;
      int sp = -1;
      for (int j = i + 1; j < n; ++j) {
        if (s[j] == s[i]) sp = j;
        if (s[j] != t[j] && s[j] == s[i]) {
          sp = j;
          break;
        }
      }
      if (~sp) {
        an.push_back({sp, i});
        swap(s[sp], t[i]);
        continue;
      }
      for (int j = i + 1; j < n; ++j) {
        if (t[j] == s[i]) sp = j;
        if (s[j] != t[j] && t[j] == s[i]) {
          sp = j;
          break;
        }
      }
      if (~sp) {
        an.push_back({sp, sp});
        swap(s[sp], t[sp]);
        an.push_back({sp, i});
        swap(s[sp], t[i]);
        continue;
      }
      break;
    }
    if (s != t || an.size() > 2 * n)
      puts("NO");
    else {
      printf("YES\n%d\n", an.size());
      for (auto i : an) printf("%d %d\n", i.first + 1, i.second + 1);
    }
  }
}
