#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 5000010;
const long long INF = 1e18;
const int null = 0x3f3f3f3f;
const int mod = 1;
template <typename T>
inline void read(T &a) {
  char c = getchar();
  T x = 0, f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  a = f * x;
}
int T, n;
string s, t;
int a[1010][2];
int b[26];
int main() {
  read(T);
  while (T--) {
    for (int i = 0; i < 26; i++) b[i] = 0;
    read(n);
    cin >> s >> t;
    for (int i = 0; i < n; i++) {
      b[s[i] - 'a']++;
      b[t[i] - 'a']++;
    }
    int flag = 0;
    for (int i = 0; i < 26; i++) {
      if (b[i] % 2) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      puts("No");
      continue;
    }
    int k = 0;
    for (int i = 0; i < n; i++) {
      int f = 1;
      if (s[i] != t[i]) {
        for (int j = i + 1; j < n; j++) {
          if (s[i] == s[j]) {
            swap(t[i], s[j]);
            a[k][0] = j;
            a[k++][1] = i;
            f = 0;
            break;
          }
        }
        for (int j = i + 1; j < n && f; j++) {
          if (s[i] == t[j]) {
            swap(s[j], t[j]);
            a[k][0] = j;
            a[k++][1] = j;
            swap(t[i], s[j]);
            a[k][0] = j;
            a[k++][1] = i;
            break;
          }
        }
      }
    }
    puts("Yes");
    cout << k << endl;
    for (int i = 0; i < k; i++) {
      cout << a[i][0] + 1 << " " << a[i][1] + 1 << endl;
    }
  }
  return 0;
}
