#include <bits/stdc++.h>
using namespace std;
long long po(long long x, long long y, long long M) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return po(x, y / 2, M) % M * po(x, y / 2, M) % M;
  else
    return x * po(x, y / 2, M) % M * po(x, y / 2, M) % M;
}
long long modInverse(long long n, long long M) { return po(n, M - 2, M); }
long long nCrModPFermat(long long n, long long r, long long M) {
  if (!r) return 1;
  long long fac[n + 1];
  fac[0] = 1;
  long long i;
  for (i = 1; i < n + 1; i++) {
    fac[i] = fac[i - 1] * i % M;
  }
  return (fac[n] * modInverse(fac[r], M) % M * modInverse(fac[n - r], M) % M) %
         M;
}
long long logk(long long a, long long b) { return log(a) / log(b); }
bool isPrime(long long N) {
  for (long long i = 2; i * i <= N; ++i) {
    if (N % i == 0) return false;
  }
  return true;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  else
    return a.first > b.first;
}
bool sortin(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  else
    return a.first < b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, i;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<long long> pos;
    vector<vector<int>> v(30), v1(30);
    for (i = 0; i < n; i++) {
      if (s1[i] != s2[i]) {
        pos.push_back(i);
      }
      int x = s2[i] - 'a';
      v[x].push_back(i);
      x = s1[i] - 'a';
      v1[x].push_back(i);
    }
    long long j, f = 0;
    for (i = 0; i < 26; i++) {
      if ((v[i].size() + v1[i].size()) % 2 != 0) {
        cout << "NO\n";
        f = 1;
        break;
      }
    }
    if (f) continue;
    vector<pair<long long, long long>> ans;
    for (i = 0; i < pos.size(); i++) {
      long long p = pos[i];
      f = 1;
      for (j = i + 1; j < pos.size(); j++) {
        long long q = pos[j];
        if (s1[p] == s1[q]) {
          swap(s2[p], s1[q]);
          ans.push_back({q + 1, p + 1});
          f = 0;
          break;
        }
      }
      if (f)
        for (j = i + 1; j < pos.size(); j++) {
          long long q = pos[j];
          if (s1[p] == s2[q]) {
            swap(s2[q], s1[pos[i + 1]]);
            swap(s2[p], s1[pos[i + 1]]);
            ans.push_back({pos[i + 1] + 1, q + 1});
            ans.push_back({pos[i + 1] + 1, p + 1});
            f = 0;
            break;
          }
        }
    }
    cout << "YES\n";
    cout << ans.size() << "\n";
    for (i = 0; i < ans.size(); i++) {
      cout << ans[i].first << " " << ans[i].second << "\n";
    }
  }
  return 0;
}
