#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf(" %d", &t);
  while (t--) {
    int n;
    scanf(" %d", &n);
    vector<set<int>> let1(26), let2(26);
    char ar1[n], ar2[n];
    for (int i = 0; i < n; ++i) {
      scanf(" %c", &ar1[i]);
      let1[ar1[i] - 'a'].insert(i);
    }
    for (int i = 0; i < n; ++i) {
      scanf(" %c", &ar2[i]);
      let2[ar2[i] - 'a'].insert(i);
    }
    bool posi = 1;
    vector<pair<int, int>> steps;
    for (int i = 0; i < n && posi; ++i) {
      if (ar1[i] != ar2[i]) {
        auto va = let1[ar1[i] - 'a'].lower_bound(i + 1);
        auto va2 = let2[ar1[i] - 'a'].begin();
        if (va != let1[ar1[i] - 'a'].end()) {
          int pos = *va;
          steps.push_back({pos, i});
          let1[ar1[i] - 'a'].erase(va);
          let1[ar2[i] - 'a'].insert(pos);
          let2[ar2[i] - 'a'].erase(i);
          swap(ar2[i], ar1[pos]);
        } else if (let2[ar1[i] - 'a'].size()) {
          int pos = *va2;
          steps.push_back({i + 1, pos});
          steps.push_back({i + 1, i});
          let1[ar1[i + 1] - 'a'].erase(i + 1);
          let2[ar2[pos] - 'a'].erase(pos);
          let2[ar1[i + 1] - 'a'].insert(pos);
          swap(ar1[i + 1], ar2[pos]);
          let1[ar2[i] - 'a'].insert(i + 1);
          let2[ar2[i] - 'a'].erase(i);
          swap(ar2[i], ar1[i + 1]);
        } else
          posi = 0;
      } else {
        let2[ar2[i] - 'a'].erase(i);
        let1[ar2[i] - 'a'].erase(i);
      }
    }
    if (!posi) {
      puts("No");
      continue;
    }
    puts("Yes");
    printf("%d\n", (int)steps.size());
    for (auto &va : steps) printf("%d %d\n", va.first + 1, va.second + 1);
  }
  return 0;
}
