#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long k;
  cin >> k;
  map<char, long long> m;
  for (long long g = 0; g < k; g++) {
    long long n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    m.clear();
    for (long long i = 0; i < n; i++) {
      m[s[i]]++;
      m[t[i]]++;
    }
    bool found = 0;
    for (map<char, long long>::iterator it = m.begin(); it != m.end(); it++)
      if ((*it).second % 2 == 1) {
        found = 1;
        break;
      }
    if (found) {
      cout << "No\n";
    } else {
      cout << "Yes\n";
      vector<pair<long long, long long> > ans;
      ans.clear();
      for (long long i = 0; i < n; i++)
        if (s[i] != t[i]) {
          for (long long j = 0; j < n; j++)
            if (i != j && t[j] != s[j]) {
              if (s[i] == s[j] || t[i] == t[j]) {
                swap(s[i], t[j]);
                ans.push_back({i, j});
                i = 0;
                break;
              }
              if (s[i] == t[j]) {
                swap(s[j], t[j]);
                swap(s[j], t[i]);
                ans.push_back({j, j});
                ans.push_back({j, i});
                i = 0;
                break;
              }
              if (t[i] == s[j]) {
                swap(s[j], t[j]);
                swap(s[i], t[j]);
                ans.push_back({j, j});
                ans.push_back({i, j});
                i = 0;
                break;
              }
            }
        }
      cout << ans.size() << endl;
      for (long long i = 0; i < ans.size(); i++)
        cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
    }
  }
}
