#include <bits/stdc++.h>
using namespace std;
long long int GCD(long long int a, long long int b) {
  return b == 0 ? a : GCD(b, a % b);
}
long long int LCM(long long int a, long long int b) {
  return a * (b / GCD(a, b));
}
int pos[105];
int a[105];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    char s[55], p[55];
    scanf("%s", s);
    scanf("%s", p);
    int cnt[30];
    memset(cnt, 0, sizeof(cnt));
    for (int i = int(0); i <= int(n - 1); i++) {
      cnt[s[i] - 'a']++;
      cnt[p[i] - 'a']++;
    }
    bool flg = true;
    for (int i = int(0); i <= int(26); i++) {
      if (cnt[i] % 2) flg = false;
    }
    if (!flg) {
      printf("NO\n");
      continue;
    }
    vector<pair<int, int> > v;
    for (int i = int(0); i <= int(n - 1); i++) {
      if (s[i] == p[i]) continue;
      bool f = true;
      if (f) {
        for (int j = int(i + 1); j <= int(n - 1); j++) {
          if (s[i] == s[j] && s[j] != p[j]) {
            f = false;
            swap(p[i], s[j]);
            v.push_back(make_pair(j, i));
            break;
          }
        }
      }
      if (f) {
        for (int j = int(i + 1); j <= int(n - 1); j++) {
          if (p[i] == p[j] && s[j] != p[j]) {
            f = false;
            swap(s[i], p[j]);
            v.push_back(make_pair(i, j));
            break;
          }
        }
      }
      if (f) {
        for (int j = int(i + 1); j <= int(n - 1); j++) {
          if (s[i] == p[j] && s[j] != p[j]) {
            f = false;
            swap(s[j], p[j]);
            v.push_back(make_pair(j, j));
            swap(p[i], s[j]);
            v.push_back(make_pair(j, i));
            break;
          }
        }
      }
      if (f) {
        for (int j = int(i + 1); j <= int(n - 1); j++) {
          if (p[i] == s[j] && s[j] != p[j]) {
            f = false;
            swap(s[j], p[j]);
            v.push_back(make_pair(j, j));
            swap(s[i], p[j]);
            v.push_back(make_pair(i, j));
            break;
          }
        }
      }
      if (f) {
        flg = false;
        break;
      }
    }
    if (flg) {
      printf("YES\n");
      printf("%d", v.size());
      printf("\n");
      for (int i = int(0); i <= int(v.size() - 1); i++) {
        printf("%d", v[i].first + 1);
        printf(" ");
        printf("%d", v[i].second + 1);
        printf("\n");
      }
    } else
      printf("NO\n");
  }
  return 0;
}
