#include <bits/stdc++.h>
using namespace std;
long long powermod(long long _a, long long _b) {
  long long _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a);
    _b /= 2;
    _a = (_a * _a);
  }
  return _r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<pair<long long, long long> > ans;
    long long f = 0;
    for (long long i = (long long)(0); i < (long long)(n); i++) {
      if (s[i] != t[i]) {
        long long tem = -1, p1 = -1, p2 = -1;
        for (long long j = i + 1; j < n; j++) {
          if (s[j] == s[i] || t[j] == t[i]) {
            tem = j;
            break;
          }
          if (t[j] == s[i]) {
            p1 = j;
          }
          if (s[j] == t[i]) {
            p2 = j;
          }
        }
        if (tem == -1 && p1 == -1 && p2 == -1) {
          f = 1;
          break;
        }
        if (tem != -1) {
          if (s[i] == s[tem]) {
            ans.push_back({tem, i});
            swap(t[i], s[tem]);
          } else {
            ans.push_back({i, tem});
            swap(s[i], t[tem]);
          }
        } else {
          if (p1 != -1 && p2 == -1) {
            ans.push_back({p1, p1});
            ans.push_back({p1, i});
            swap(s[p1], t[p1]);
            swap(t[i], s[p1]);
          } else if (p2 != -1 && p1 == -1) {
            ans.push_back({p2, p2});
            ans.push_back({i, p2});
            swap(s[p2], t[p2]);
            swap(s[i], t[p2]);
          } else {
            if (p1 < p2) {
              ans.push_back({p1, p1});
              ans.push_back({p1, i});
              swap(s[p1], t[p1]);
              swap(t[i], s[p1]);
            } else {
              ans.push_back({p2, p2});
              ans.push_back({i, p2});
              swap(s[p2], t[p2]);
              swap(s[i], t[p2]);
            }
          }
        }
      }
    }
    if (ans.size() > 2 * n) f = 1;
    if (f == 1)
      cout << "No" << '\n';
    else {
      cout << "Yes" << '\n';
      cout << ans.size() << '\n';
      for (long long i = (long long)(0); i < (long long)(ans.size()); i++) {
        cout << ans[i].first + 1 << " " << ans[i].second + 1 << '\n';
      }
    }
  }
}
