#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
int T;
int n;
char s[N], t[N];
int a[N], c[N];
vector<pair<int, int> > vc;
int main() {
  cin >> T;
  while (T--) {
    scanf("%d", &n);
    scanf("%s", s);
    scanf("%s", t);
    fill(c, c + 26, 0);
    for (int i = 0; i < n; i++) c[s[i] - 'a']++, c[t[i] - 'a']++;
    for (int i = 0; i < 26; i++)
      if (c[i] & 1) n = 0;
    if (!n)
      puts("No");
    else {
      vc.clear();
      for (int i = 0; i < n; i++) {
        if (s[i] == t[i]) continue;
        bool flg = 0;
        for (int j = i + 1; j < n; j++)
          if (s[i] == s[j]) {
            vc.push_back(pair<int, int>(j, i));
            swap(t[i], s[j]);
            flg = 1;
            break;
          }
        if (!flg) {
          for (int j = i + 1; j < n; j++)
            if (s[i] == t[j]) {
              vc.push_back(pair<int, int>(j, j));
              swap(s[j], t[j]);
              vc.push_back(pair<int, int>(j, i));
              swap(s[j], t[i]);
              break;
            }
        }
      }
      puts("Yes");
      printf("%d\n", (int)vc.size());
      for (pair<int, int> p : vc) {
        printf("%d %d\n", p.first + 1, p.second + 1);
      }
    }
  }
  return 0;
}
