#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int t, n;
string s1, s2, temp;
vector<pair<int, int> > pre;
int Find(string s, char ch, int x) {
  for (int i = x + 1; i < n; ++i)
    if (s[i] == ch) return i;
  return -1;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    pre.clear();
    scanf("%d", &n);
    cin >> s1 >> s2;
    int num1[200] = {0};
    for (int i = 0; i < n; ++i) {
      if (s1[i] == s2[i]) continue;
      num1[s1[i]]++, num1[s2[i]]++;
    }
    int flag = true;
    for (int i = 'a'; i <= 'z'; ++i)
      if (num1[i] % 2 != 0 || num1[i] % 2 != 0) {
        flag = false;
        break;
      }
    if (!flag)
      puts("NO");
    else {
      int cnt = 0;
      for (int i = 0; i < n; ++i) {
        if (s1[i] != s2[i]) {
          temp = "";
          temp += s1[i];
          int x = Find(s1, s1[i], i);
          if (x == -1) {
            int y;
            for (int j = i + 1; j < n; ++j) {
              if (s1[j] != s2[j]) {
                y = j;
                break;
              }
            }
            temp = "";
            temp += s1[i];
            y = Find(s2, s1[i], i);
            swap(s2[y], s1[y]);
            pre.push_back(pair<int, int>(y + 1, y + 1));
            pre.push_back(pair<int, int>(y + 1, i + 1));
            swap(s1[y], s2[i]);
            cnt += 2;
          } else {
            swap(s2[i], s1[x]);
            pre.push_back(pair<int, int>(x + 1, i + 1));
            cnt++;
          }
        }
      }
      if (cnt <= 2 * n) {
        puts("YES");
        printf("%d\n", cnt);
        for (int i = 0; i < pre.size(); ++i)
          printf("%d %d\n", pre[i].first, pre[i].second);
      } else
        puts("NO");
    }
  }
  return 0;
}
