#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 1;
const long long LINF = 1e18 + 1;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int alp[26] = {};
  for (int(i) = (0); (i) < (n); (i)++) {
    alp[s[i] - 'a']++;
    alp[t[i] - 'a']++;
  }
  for (int(i) = (0); (i) < (26); (i)++) {
    if (alp[i] % 2) {
      cout << ("No") << endl;
      return;
    }
  }
  cout << ("Yes") << endl;
  vector<pair<int, int> > pos;
  int cnt = 0;
  while (cnt < n) {
    if (s[cnt] == t[cnt]) {
      cnt++;
      continue;
    }
    for (int(i) = (cnt + 1); (i) < (n); (i)++) {
      if (s[i] == s[cnt]) {
        swap(s[i], t[cnt]);
        pos.push_back(make_pair(i + 1, cnt + 1));
        cnt++;
        continue;
      }
    }
    for (int(i) = (cnt + 1); (i) < (n); (i)++) {
      if (t[i] == s[cnt]) {
        swap(s[cnt + 1], t[i]);
        pos.push_back(make_pair(cnt + 2, i + 1));
        swap(s[cnt + 1], t[cnt]);
        pos.push_back(make_pair(cnt + 2, cnt + 1));
        cnt++;
        continue;
      }
    }
  }
  cout << (pos.size()) << endl;
  for (int(i) = (0); (i) < (pos.size()); (i)++) {
    cout << (pos[i].first) << ' ';
    cout << (pos[i].second) << endl;
  }
}
int main(void) {
  int k;
  cin >> k;
  for (int(i) = (0); (i) < (k); (i)++) solve();
  return 0;
}
