#include <bits/stdc++.h>
using namespace std;
const int mxn = 3e5 + 9;
const int mod = 1e9 + 7;
long long n, k, m, ans = 0;
long long a[mxn];
int found(string s, int idx, char ch) {
  for (int i = idx + 1; i < n; i++) {
    if (ch == s[i]) return i;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  int tc;
  cin >> tc;
  while (tc--) {
    string s, t;
    cin >> n >> s >> t;
    map<char, int> mp;
    for (int i = 0; i < n; i++) {
      mp[s[i]]++;
      mp[t[i]]++;
    }
    bool f = true;
    for (auto ele : mp) {
      if (ele.second % 2) f = false;
    }
    if (!f) {
      cout << "No\n";
      continue;
    }
    vector<pair<int, int> > out;
    for (int i = 0; i < n; i++) {
      if (s[i] == t[i]) continue;
      int j = found(s, i, s[i]);
      if (j) {
        swap(s[j], t[i]);
        out.push_back({j, i});
      } else {
        j = found(t, i, s[i]);
        swap(s[j], t[j]);
        out.push_back({j, j});
        swap(s[j], t[i]);
        out.push_back({j, i});
      }
    }
    cout << "Yes\n" << out.size() << endl;
    for (auto z : out) {
      cout << z.first + 1 << " " << z.second + 1 << endl;
    }
  }
  return 0;
}
