#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) { return (a < b) ? a : b; }
long long int max(long long int a, long long int b) { return (a > b) ? a : b; }
long long int fp(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int x = fp(a, b / 2);
  x = (x * x) % 1000000007;
  if (b & 1) x = (x * a) % 1000000007;
  return x;
}
void c_p_c() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
}
signed main() {
  c_p_c();
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    char s[n + 1], t[n + 1];
    cin >> s >> t;
    long long int freq[26] = {0};
    for (long long int i = 0; i < n; i++) {
      freq[s[i] - 'a']++;
      freq[t[i] - 'a']++;
    }
    long long int f = 0;
    for (long long int i : freq) {
      if (i % 2 != 0) {
        f = 1;
        break;
      }
    }
    if (f == 1)
      cout << "No"
           << "\n";
    else {
      cout << "Yes"
           << "\n";
      long long int ans[2][2 * n];
      long long int times = 0;
      for (long long int i = 0; i < n; i++) {
        if (s[i] != t[i]) {
          for (long long int j = i + 1; j < n; j++) {
            if (s[j] == s[i]) {
              swap(t[i], s[j]);
              ans[0][times] = j + 1;
              ans[1][times] = i + 1;
              times++;
              break;
            } else if (t[j] == s[i]) {
              swap(t[j], s[j]);
              ans[0][times] = j + 1;
              ans[1][times] = j + 1;
              times++;
              swap(t[i], s[j]);
              ans[0][times] = j + 1;
              ans[1][times] = i + 1;
              times++;
              break;
            }
          }
        }
      }
      cout << times << "\n";
      for (long long int i = 0; i < times; i++)
        cout << ans[0][i] << " " << ans[1][i] << "\n";
    }
  }
}
