#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int maxm = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxblock = sqrt(maxn) + 10;
const double eps = 1e-7;
const long long INF = 1e16;
int n;
char str1[maxn], str2[maxn];
vector<pair<int, int> > v;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    v.clear();
    scanf("%d", &n);
    scanf("%s%s", str1 + 1, str2 + 1);
    for (int i = 1; i <= n; i++) {
      if (str1[i] == str2[i]) continue;
      int findflag = 0;
      for (int j = i + 1; j <= n; j++) {
        if (str2[j] == str2[i]) {
          v.push_back(make_pair(i, j));
          swap(str1[i], str2[j]);
          findflag = 1;
          break;
        }
      }
      if (!findflag) {
        for (int j = i + 1; j <= n; j++) {
          if (str1[j] == str2[i]) {
            v.push_back(make_pair(j, j));
            swap(str1[j], str2[j]);
            v.push_back(make_pair(i, j));
            swap(str1[i], str2[j]);
            break;
          }
        }
      }
    }
    int flag = 1;
    for (int i = 1; i <= n; i++) flag &= (str1[i] == str2[i]);
    if (!flag)
      printf("NO\n");
    else {
      printf("Yes\n");
      printf("%d\n", v.size());
      for (int i = 0; i < v.size(); i++) {
        printf("%d %d\n", v[i].first, v[i].second);
      }
    }
  }
  return 0;
}
