#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
    }
    b >>= 1;
    a = (a * a);
  }
  return res;
}
void solve() {
  long long int n, flag = 0;
  cin >> n;
  string s, t;
  cin >> s >> t;
  long long int coun[26] = {0};
  for (int i = 0; i < n; i++) coun[s[i] - 'a']++, coun[t[i] - 'a']++;
  for (int i = 0; i < 26; i++) {
    if (coun[i] % 2) {
      cout << "NO" << endl;
      return;
    }
  }
  long long int m = 0;
  vector<pair<long long int, long long int> > v;
  for (int i = 0; i < n; i++) {
    if (s[i] == t[i]) continue;
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        m++;
        v.push_back(make_pair(j + 1, i + 1));
        char temp = s[j];
        s[j] = t[i];
        t[i] = temp;
        break;
      } else if (s[i] == t[j]) {
        m += 2;
        swap(t[j], s[j]);
        v.push_back(make_pair(j + 1, j + 1));
        swap(s[j], t[i]);
        v.push_back(make_pair(j + 1, i + 1));
        break;
      }
    }
  }
  if (s == t) {
    cout << "YES" << endl;
    cout << m << endl;
    for (int i = 0; i < m; i++)
      cout << v[i].first << " " << v[i].second << endl;
  } else
    cout << "NO" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
