#include <bits/stdc++.h>
using namespace std;
bool check(string s) {
  unordered_map<char, int> mp;
  for (int i = 0; i < s.length(); i++) {
    mp[s[i]] += 1;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if ((it->second) % 2 != 0) {
      return false;
    }
  }
  return true;
}
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  string s1 = "", t1 = "";
  unordered_map<int, int> mp1;
  for (int i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      mp1[s1.length()] = i;
      s1.push_back(s[i]);
      t1.push_back(t[i]);
    }
  }
  if (check(s1 + t1) == false) {
    cout << "No" << endl;
    return;
  }
  cout << "Yes" << endl;
  int n1 = s1.length();
  unordered_map<char, vector<int>> mp;
  for (int i = 0; i < n1; i++) {
    mp[t1[i]].push_back(i);
  }
  vector<pair<int, int>> res;
  for (int i = 0; i < n1; i++) {
    mp[t1[i]].erase(find(mp[t1[i]].begin(), mp[t1[i]].end(), i));
    if (s1[i] == t1[i]) {
      continue;
    }
    if (mp[t1[i]].size() == 0) {
      if (mp.find(s1[i]) == mp.end() || mp[s1[i]].size() == 0) {
        int nextInd = i;
        for (int j = i + 1; j < s1.length(); j++) {
          if (s1[j] == s1[i]) {
            nextInd = j;
            break;
          }
        }
        res.push_back({mp1[nextInd], mp1[i]});
        swap(s1[nextInd], t1[i]);
        continue;
      } else {
        res.push_back({mp1[i], mp1[i]});
        swap(s1[i], t1[i]);
      }
    }
    int sw1 = i, sw2 = mp[t1[i]][0];
    mp[t1[i]].erase(find(mp[t1[i]].begin(), mp[t1[i]].end(), sw2));
    mp[s1[i]].push_back(sw2);
    res.push_back({mp1[sw1], mp1[sw2]});
    swap(s1[sw1], t1[sw2]);
  }
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); i++) {
    cout << (res[i].first + 1) << " " << (res[i].second) + 1 << endl;
  }
}
int main() {
  long long q = 1;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
