#include <bits/stdc++.h>
using namespace std;
char a[55], b[55];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    scanf("%s%s", a + 1, b + 1);
    vector<pair<int, int> > ans;
    int bad = 0;
    for (int i = 1; i < n; i++) {
      if (a[i] == b[i]) continue;
      int enter = 0;
      for (int j = i + 1; j <= n; j++) {
        if (a[i] == a[j]) {
          enter = 1;
          ans.push_back({j, i});
          swap(a[j], b[i]);
          break;
        }
      }
      if (enter) continue;
      for (int j = i + 1; j <= n; j++) {
        if (a[i] == b[j]) {
          enter = 1;
          swap(a[n], b[j]);
          ans.push_back({n, j});
          swap(a[n], b[i]);
          ans.push_back({n, i});
          break;
        }
      }
      if (!enter) {
        bad = 1;
        break;
      }
    }
    if (!bad) {
      if (a[n] == b[n]) {
        printf("Yes\n");
        printf("%d\n", (int)ans.size());
        for (auto o : ans) printf("%d %d\n", o.first, o.second);
      } else
        printf("No\n");
    } else
      printf("No\n");
  }
  return 0;
}
