#include <bits/stdc++.h>
using namespace std;
const int N = 55;
char s[N], t[N];
int a[1010][2];
int n;
void solve() {
  int len = 0;
  for (int i = 0; i < n; i++) {
    int flag = 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[len][0] = j;
          a[len++][1] = i;
          flag = 0;
          break;
        }
      }
      for (int j = i + 1; j < n && flag; j++) {
        if (s[i] == t[j]) {
          swap(s[j], t[j]);
          a[len][0] = j;
          a[len++][1] = j;
          swap(t[i], s[j]);
          a[len][0] = j;
          a[len++][1] = i;
          break;
        }
      }
    }
  }
  cout << "Yes\n" << len << endl;
  for (int i = 0; i < len; i++) {
    cout << a[i][0] + 1 << " " << a[i][1] + 1 << endl;
  }
}
int main() {
  int k;
  cin >> k;
  while (k--) {
    cin >> n;
    cin >> s >> t;
    map<char, int> vis;
    for (int i = 0; i < n; i++) {
      vis[s[i]]++;
      vis[t[i]]++;
    }
    int flag = 1;
    for (int i = 0; i < n; i++) {
      if (vis[s[i]] % 2 || vis[t[i]] % 2) {
        cout << "No\n";
        flag = 0;
        break;
      }
    }
    if (flag) solve();
  }
  return 0;
}
