#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int t, n;
  bool flag;
  string s1, s2;
  cin >> t;
  for (int tt = 0; tt < (t); tt++) {
    flag = false;
    cin >> n;
    cin >> s1;
    cin >> s2;
    unordered_map<int, int> i2c, c2i;
    vector<int> v, pos;
    vector<pair<int, int> > vo;
    v.assign(26, 0);
    for (auto c : s1) v[c - 97]++;
    for (auto c : s2) v[c - 97]++;
    for (int i = 0; i < (26); i++) {
      if (v[i] % 2) {
        flag = true;
        break;
      }
    }
    if (flag) {
      cout << "No\n";
      continue;
    }
    cout << "Yes\n";
    for (int i = 0; i < (n - 1); i++) {
      flag = false;
      if (s1[i] != s2[i]) {
        for (int j = i + 1; j < (n); j++) {
          if (s1[j] == s1[i]) {
            vo.push_back(pair<int, int>{j + 1, i + 1});
            s1[j] = s2[i];
            s2[i] = s1[i];
            flag = true;
          }
          if (flag) break;
        }
        if (flag) continue;
        for (int j = i + 1; j < (n); j++) {
          if (s2[j] == s1[i]) {
            vo.push_back(pair<int, int>{i + 2, j + 1});
            vo.push_back(pair<int, int>{i + 2, i + 1});
            s2[j] = s1[i + 1];
            s1[i + 1] = s2[i];
            s2[i] = s1[i];
            flag = true;
          }
          if (flag) break;
        }
      }
    }
    cout << vo.size() << '\n';
    for (int i = 0; i < ((int)vo.size()); i++) {
      cout << vo[i].first << " " << vo[i].second << '\n';
    }
  }
  return 0;
}
