#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    map<char, long long int> cnt;
    for (long long int i = 0; i < n; i++) {
      cnt[s[i]]++;
      cnt[t[i]]++;
    }
    long long int flag = 0;
    for (auto i : cnt)
      if (i.second % 2) flag = 1;
    if (flag) {
      cout << "No\n";
      continue;
    }
    vector<pair<long long int, long long int> > ans;
    for (long long int i = 0; i < n - 1; i++) {
      char ch = s[i];
      long long int flag = 0;
      for (long long int j = i + 1; j < n; j++) {
        if (s[j] == ch) {
          swap(t[i], s[j]);
          ans.push_back({j, i});
          flag = 1;
          break;
        }
      }
      if (flag) continue;
      long long int pos;
      for (long long int j = i; j < n; j++) {
        if (ch == t[j]) {
          pos = j;
        }
      }
      swap(t[pos], s[n - 1]);
      swap(s[n - 1], t[i]);
      ans.push_back({n - 1, pos});
      ans.push_back({n - 1, i});
    }
    cout << "Yes\n";
    cout << ans.size() << endl;
    for (auto i : ans) {
      cout << i.first + 1 << " " << i.second + 1 << endl;
    }
  }
}
