#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 3;
const int mod = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int M = 1 << 20 << 1;
const int N = 3e6 + 5;
char s[maxn], t[maxn];
int c[maxn];
vector<pair<int, int> > ans;
int solve() {
  int n;
  cin >> n;
  cin >> s;
  cin >> t;
  for (int i = (0); i < (26); i++) c[i] = 0;
  for (int i = (0); i < (n); i++) c[s[i] - 'a']++, c[t[i] - 'a']++;
  for (int i = (0); i < (26); i++)
    if (c[i] & 1) return 0;
  ans.clear();
  while (1) {
    for (int i = (0); i < (n); i++)
      for (int j = (0); j < (n); j++)
        if (i != j && s[i] == s[j] && s[i] != t[i] && s[j] != t[j]) {
          ans.push_back(make_pair(i, j));
          swap(s[i], t[j]);
        }
    for (int i = (0); i < (n); i++) {
      for (int j = (0); j < (n); j++)
        if (s[i] != t[i] && s[i] == t[j] && s[j] != t[j]) {
          ans.push_back(make_pair(i, i)), swap(s[i], t[i]);
          ans.push_back(make_pair(i, j)), swap(s[i], t[j]);
        }
    }
    int f = 0;
    for (int i = (0); i < (n); i++)
      if (s[i] != t[i]) {
        f = 1;
        break;
      }
    if (f) continue;
    break;
  }
  assert(((int)ans.size() <= 2 * n));
  cout << "Yes\n";
  cout << (int)ans.size() << "\n";
  for (int i = (0); i < ((int)ans.size()); i++) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << "\n";
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    if (!solve()) cout << "No\n";
  }
  return 0;
}
