#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
int vis[200];
int pre[200];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    string a, b;
    cin >> a >> b;
    memset(vis, 0, sizeof(vis));
    ans.clear();
    for (int i = 0; i < a.size(); i++) {
      vis[a[i]]++;
    }
    for (int i = 0; i < b.size(); i++) {
      vis[b[i]]++;
    }
    int f = 0;
    for (int i = 'a'; i <= 'z'; i++) {
      if (vis[i] % 2 != 0) {
        f = 1;
      }
    }
    if (f) {
      printf("No\n");
    } else {
      printf("Yes\n");
      int pos = 0;
      for (int i = 0; i < a.size(); i++) {
        if (a[i] != b[i]) {
          int flag = 0;
          for (int j = i + 1; j < b.size(); j++) {
            if (b[j] == a[i]) {
              swap(b[j], a[j]);
              swap(a[j], b[i]);
              ans.push_back(make_pair(j + 1, j + 1));
              ans.push_back(make_pair(j + 1, i + 1));
              flag = 1;
              break;
            }
          }
          if (flag == 0) {
            for (int j = i + 1; j < a.size(); j++) {
              if (a[j] == a[i]) {
                swap(a[j], b[i]);
                ans.push_back(make_pair(j + 1, i + 1));
                break;
              }
            }
          }
        }
      }
      printf("%d\n", ans.size());
      for (int i = 0; i < ans.size(); i++) {
        printf("%d %d\n", ans[i].first, ans[i].second);
      }
    }
  }
}
