#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e6 + 5;
const long long inf = 1e10;
const long long mod = 1e9 + 7;
long long k, n;
string s, t;
vector<pair<long long, long long> > res;
long long cnt[100];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> k;
  while (k--) {
    cin >> n;
    memset(cnt, 0LL, sizeof(cnt));
    res.clear();
    cin >> s >> t;
    for (long long i = 0; i <= n - 1; i++) {
      cnt[s[i] - 'a']++;
      cnt[t[i] - 'a']++;
    }
    long long ok = 1;
    for (long long i = 0; i <= 25; i++) {
      if (cnt[i] % 2) {
        cout << "No" << endl;
        ok = 0;
        break;
      }
    }
    if (ok) {
      long long tmp = 1;
      long long flag = 0;
      for (long long i = 0; i <= n - 1; i++) {
        if (s[i] != t[i]) {
          flag = 0;
          for (long long j = i + 1; j <= n - 1; j++) {
            if (s[j] == s[i]) {
              res.push_back(pair<long long, long long>(j + 1, i + 1));
              swap(s[j], t[i]);
              flag = 1;
              break;
            }
          }
          if (!flag) {
            for (long long j = i + 1; j <= n - 1; j++) {
              if (t[j] == s[i]) {
                res.push_back(pair<long long, long long>(i + 1 + 1, j + 1));
                swap(s[i + 1], t[j]);
                res.push_back(pair<long long, long long>(i + 1 + 1, i + 1));
                swap(s[i + 1], t[i]);
                break;
              }
            }
          }
        }
      }
      cout << "Yes" << endl;
      cout << res.size() << endl;
      if (res.size())
        for (long long i = 0; i <= res.size() - 1; i++)
          cout << res[i].first << " " << res[i].second << endl;
    }
  }
  return 0;
}
