#include <bits/stdc++.h>
using namespace std;
int main() {
  int c[26];
  int a_P[55], b_P[55];
  int ans[110][2];
  int t, n;
  string a, b;
  cin >> t;
  while (t--) {
    int pos = 0;
    int cnt = 0;
    memset(c, 0, sizeof(c));
    cin >> n;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      c[a[i] - 'a']++;
      c[b[i] - 'a']++;
      if (a[i] != b[i]) {
        a_P[pos] = i;
        b_P[pos++] = i;
      }
    }
    int ok = 1;
    for (int i = 0; i < 26; i++) {
      if (c[i] % 2) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      cout << "Yes" << endl;
      for (int i = 0; i < pos; i++) {
        for (int j = i + 1; j < pos; j++) {
          if (a[a_P[i]] == a[a_P[j]] && a_P[i] != -1 && b_P[i] != -1) {
            ans[cnt][0] = a_P[j] + 1;
            ans[cnt++][1] = b_P[i] + 1;
            swap(a[a_P[j]], b[b_P[i]]);
            a_P[i] = -1;
            b_P[i] = -1;
            break;
          }
          if (a[a_P[i]] == b[b_P[j]] && b_P[j] != -1) {
            ans[cnt][0] = a_P[j] + 1;
            ans[cnt++][1] = b_P[j] + 1;
            swap(a[a_P[j]], b[b_P[j]]);
            ans[cnt][0] = a_P[j] + 1;
            ans[cnt++][1] = b_P[i] + 1;
            swap(a[a_P[j]], b[b_P[i]]);
            a_P[i] = -1;
            b_P[i] = -1;
            break;
          }
        }
      }
      cout << cnt << endl;
      for (int i = 0; i < cnt; i++)
        cout << ans[i][0] << " " << ans[i][1] << endl;
    } else
      cout << "No" << endl;
  }
  return 0;
}
