#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long mod) {
  if (b == 0 || a == 1) return mod == 1 ? 0 : 1;
  if (b % 2 == 0) {
    long long k = powmod(a, b / 2, mod);
    return (k * k) % mod;
  } else {
    long long k = powmod(a, b / 2, mod);
    return ((k * k) % mod * a) % mod;
  }
}
int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
bool is_prime(int n) {
  int bound = sqrt(n);
  int d = 2;
  while (d <= bound && n % d != 0) ++d;
  return d * d > n;
}
void sort(vector<long long> &a) { sort(a.begin(), a.end()); }
void sort(vector<int> &a) { sort(a.begin(), a.end()); }
void sort(vector<pair<long long, long long>> &a) { sort(a.begin(), a.end()); }
void sort(vector<pair<int, int>> &a) { sort(a.begin(), a.end()); }
void rev(vector<long long> &a) { reverse(a.begin(), a.end()); }
void rev(vector<int> &a) { reverse(a.begin(), a.end()); }
void rev(vector<pair<long long, long long>> &a) { reverse(a.begin(), a.end()); }
void rev(vector<pair<int, int>> &a) { reverse(a.begin(), a.end()); }
void rev(string &a) { reverse(a.begin(), a.end()); }
const int MOD = 1000000007;
const int INF = 1000000050;
const int MAXN = 100010;
const double EPS = 1e-9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt;
  cin >> tt;
  for (int i = 0; i < tt; i++) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    vector<int> cnt(26, 0);
    for (int j = 0; j < n; j++) {
      ++cnt[a[j] - 'a'];
      ++cnt[b[j] - 'a'];
    }
    bool pos = true;
    for (int j = 0; j < 26; j++) {
      if (cnt[j] % 2 != 0) pos = false;
    }
    if (pos) {
      cout << "Yes\n";
      vector<pair<int, int>> acts;
      for (int j = 0; j < n; j++) {
        if (a[j] == b[j]) continue;
        for (int k = 0; k < n; k++) {
          if (a[k] == b[k] || k == j) continue;
          if (a[k] == a[j]) {
            acts.push_back({k + 1, j + 1});
            swap(a[k], b[j]);
            break;
          } else if (b[k] == b[j]) {
            acts.push_back({j + 1, k + 1});
            swap(b[k], a[j]);
            break;
          } else if (a[k] == b[j]) {
            acts.push_back({k + 1, k + 1});
            swap(a[k], b[k]);
            acts.push_back({j + 1, k + 1});
            swap(a[j], b[k]);
            break;
          } else if (b[k] == a[j]) {
            acts.push_back({k + 1, k + 1});
            swap(a[k], b[k]);
            acts.push_back({k + 1, j + 1});
            swap(a[k], b[j]);
            break;
          }
        }
      }
      cout << acts.size() << '\n';
      for (auto p : acts) cout << p.first << ' ' << p.second << '\n';
    } else {
      cout << "No\n";
    }
  }
}
