#include <bits/stdc++.h>
using namespace std;
int n, m, k;
map<char, int> mm;
void input() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> k;
  while (k--) {
    cin >> n;
    string s, t;
    cin >> s >> t;
    s = " " + s;
    t = " " + t;
    for (int i = 1; i <= n; i++) {
      mm[s[i]]++;
      mm[t[i]]++;
    }
    vector<pair<int, int> > res;
    for (auto i : mm) {
      if (i.second % 2 == 1) {
        cout << "No\n";
        goto flash;
      }
    }
    for (int i = 1; i <= n; i++) {
      char temp = s[i];
      if (s[i] == t[i]) continue;
      for (int j = i + 1; j <= n; j++) {
        if (s[j] == temp) {
          res.push_back({j, i});
          swap(s[j], t[i]);
          goto hasagi;
        }
      }
      for (int j = i + 1; j <= n; j++) {
        if (t[j] == temp) {
          res.push_back({n, j});
          swap(s[n], t[j]);
          res.push_back({n, i});
          swap(s[n], t[i]);
          break;
        }
      }
    hasagi:;
    }
    cout << "Yes\n";
    cout << res.size() << "\n";
    for (pair<int, int> i : res) {
      cout << i.first << " " << i.second << "\n";
    }
  flash:;
    res.clear();
    mm.clear();
  }
}
int main() {
  input();
  return 0;
}
