#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
const int INF32 = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1.0e-8;
char S[MAXN], T[MAXN];
int Cnt[30];
pair<int, int> Ans[MAXN];
int Acnt;
int n;
int main() {
  int Cas;
  scanf("%d", &Cas);
  while (Cas--) {
    memset(Cnt, 0, sizeof(Cnt));
    scanf("%d", &n);
    scanf("%s%s", S + 1, T + 1);
    for (int i = 1; i <= n; ++i) {
      Cnt[S[i] - 'a']++;
      Cnt[T[i] - 'a']++;
    }
    int flag = 1;
    for (char i = 'a'; i <= 'z'; ++i) {
      if (Cnt[i - 'a'] % 2) {
        flag = 0;
        break;
      }
    }
    if (flag == 0) {
      printf("NO\n");
      continue;
    }
    Acnt = 0;
    for (int i = 1, j; i <= n; ++i) {
      if (S[i] == T[i]) continue;
      for (j = i + 1; j <= n; ++j) {
        if (S[j] == S[i]) break;
      }
      if (j <= n) {
        Ans[++Acnt] = make_pair(j, i);
        swap(S[j], T[i]);
        continue;
      }
      for (j = i + 1; j <= n; ++j) {
        if (T[j] == S[i]) break;
      }
      Ans[++Acnt] = make_pair(j, j);
      swap(S[j], T[j]);
      Ans[++Acnt] = make_pair(j, i);
      swap(S[j], T[i]);
    }
    printf("YES\n%d\n", Acnt);
    for (int i = 1; i <= Acnt; ++i)
      printf("%d %d\n", Ans[i].first, Ans[i].second);
  }
}
