#include <bits/stdc++.h>
using namespace std;
long long modExp(long long a, long long b, long long c) {
  a %= c;
  long long ans = 1;
  for (; b; b >>= 1) {
    if (b & 1) {
      ans *= a;
      ans %= c;
    }
    a *= a;
    a %= c;
  }
  return ans;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long k, n;
  cin >> k;
  while (k--) {
    cin >> n;
    string a, b;
    cin >> a >> b;
    long long i, ca[26] = {0}, cb[26] = {0};
    set<long long> sa[26], sb[26];
    for (i = 0; i < n; i++) {
      ca[a[i] - 'a']++;
      cb[b[i] - 'a']++;
      sa[a[i] - 'a'].insert(i);
      sb[b[i] - 'a'].insert(i);
    }
    for (i = 0; i < 26; i++) {
      if ((ca[i] + cb[i]) & 1) break;
    }
    if (i < 26) {
      cout << "No\n";
      continue;
    }
    vector<pair<long long, long long> > ans;
    for (i = 0; i < n; i++) {
      sa[a[i] - 'a'].erase(i);
      if (a[i] == b[i]) {
        sb[b[i] - 'a'].erase(i);
        continue;
      }
      if (sa[a[i] - 'a'].empty()) {
        long long x = *sb[a[i] - 'a'].begin();
        sa[a[x] - 'a'].erase(x);
        sb[a[x] - 'a'].insert(x);
        sb[b[x] - 'a'].erase(x);
        sa[b[x] - 'a'].insert(x);
        swap(a[x], b[x]);
        sa[a[x] - 'a'].erase(x);
        sa[b[i] - 'a'].insert(x);
        sb[b[i] - 'a'].erase(i);
        sb[a[x] - 'a'].insert(i);
        swap(a[x], b[i]);
        ans.push_back({x, x});
        ans.push_back({x, i});
      } else {
        long long x = *sa[a[i] - 'a'].begin();
        sa[a[x] - 'a'].erase(x);
        sa[b[i] - 'a'].insert(x);
        sb[b[i] - 'a'].erase(i);
        sb[a[x] - 'a'].insert(i);
        swap(a[x], b[i]);
        ans.push_back({x, i});
      }
      sb[b[i] - 'a'].erase(i);
    }
    if (a != b) {
      cout << "No\n";
      continue;
    }
    cout << "Yes\n" << (long long)ans.size() << "\n";
    long long x = ans.size();
    for (i = 0; i < x; i++) {
      cout << ans[i].first + 1 << " " << ans[i].second + 1 << "\n";
    }
  }
  return 0;
}
