#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
char a[2102100];
char b[2102100];
int num[2100];
int ans[210000];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    cin >> a >> b;
    memset(num, 0, sizeof num);
    for (int i = 0; i < n; i++) {
      num[a[i]]++;
      num[b[i]]++;
    }
    int ju = 1;
    for (int i = 'a'; i <= 'z'; i++) {
      if (num[i] % 2) {
        printf("NO\n");
        ju = 0;
        break;
      } else {
        num[i] /= 2;
      }
    }
    int u = -1, t = 0;
    if (ju) {
      for (int i = 0; i < n; i++) {
        if (a[i] == b[i])
          continue;
        else {
          int jj = 1;
          for (int j = i + 1; j < n; j++) {
            if (a[j] == a[i]) {
              jj = 0;
              t++;
              swap(a[j], b[i]);
              ans[2 * t] = j;
              ans[2 * t + 1] = i;
              break;
            }
          }
          if (jj)
            for (int j = i + 1; j < n; j++) {
              if (b[j] == a[i]) {
                t++;
                swap(b[j], a[n - 1]);
                ans[2 * t] = n - 1;
                ans[2 * t + 1] = j;
                t++;
                swap(b[i], a[n - 1]);
                ans[2 * t] = n - 1;
                ans[2 * t + 1] = i;
                break;
              }
            }
        }
      }
    } else {
      continue;
    }
    printf("YES\n");
    if (t)
      printf("%d\n", t);
    else {
      printf("1\n");
      printf("1 1\n");
    }
    for (int i = 1; i <= t; i++) {
      printf("%d %d\n", ans[i * 2] + 1, ans[i * 2 + 1] + 1);
    }
  }
}
