#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long b[26] = {0};
  string x, y;
  cin >> x >> y;
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < n; i++) {
    b[x[i] - 'a']++;
    b[y[i] - 'a']++;
  }
  for (long long i = 0; i < 26; i++) {
    if (b[i] % 2 == 1) {
      cout << "No\n";
      return;
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    if (x[i] == y[i]) continue;
    char c = x[i];
    long long f = 0;
    for (long long j = i + 1; j < n; j++) {
      if (x[j] == c) {
        swap(x[j], y[i]);
        v.push_back({j + 1, i + 1});
        f = 1;
        break;
      }
    }
    if (!f) {
      for (long long j = i + 1; j < n; j++) {
        if (y[j] == c) {
          swap(x[n - 1], y[j]);
          swap(x[n - 1], y[i]);
          v.push_back({n, j + 1});
          v.push_back({n, i + 1});
          break;
        }
      }
    }
  }
  cout << "Yes\n";
  cout << v.size() << '\n';
  for (long long i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
