#include <bits/stdc++.h>
using namespace std;
void comp() {
  long long i, j, k, n, q;
  cin >> n;
  string s, t;
  cin >> s >> t;
  map<char, long long> m1;
  for (i = 0; i < n; i++) {
    m1[s[i]]++;
    m1[t[i]]++;
  }
  for (i = 0; i < 26; i++) {
    if (m1[i + 'a'] % 2) {
      cout << "No\n";
      return;
    }
  }
  vector<pair<int, int> > v1;
  for (i = 0; i < n; i++) {
    if (s[i] == t[i]) continue;
    for (j = i + 1; j < n; j++) {
      if (s[j] == s[i]) {
        swap(s[j], t[i]);
        v1.push_back(make_pair(j + 1, i + 1));
        break;
      }
    }
    if (s[i] == t[i]) continue;
    for (j = i + 1; j < n; j++) {
      if (t[j] == s[i]) {
        swap(t[j], s[i + 1]);
        v1.push_back(make_pair(i + 2, j + 1));
        swap(t[i], s[i + 1]);
        v1.push_back(make_pair(i + 2, i + 1));
        break;
      }
    }
  }
  if (v1.size() > 2 * n) assert(0);
  cout << "YES\n";
  cout << v1.size() << endl;
  for (i = 0; i < v1.size(); i++) {
    cout << v1[i].first << " " << v1[i].second << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  long long i = 0, t;
  cin >> t;
  while (t--) {
    comp();
  }
}
