#include <bits/stdc++.h>
using namespace std;
long long Min(long long a, long long b) {
  if (a >= b)
    return b;
  else
    return a;
}
long long Max(long long a, long long b) {
  if (a >= b)
    return a;
  else
    return b;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long k;
  cin >> k;
  while (k--) {
    long long n, i, flag = 0, j;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<long long> f(26, 0);
    for (i = 0; i < n; ++i) {
      f[s[i] - 97]++;
      f[t[i] - 97]++;
    }
    for (i = 0; i < 26; i++) {
      if (f[i] % 2 == 1) {
        cout << "No" << endl;
        flag = 1;
        break;
      }
    }
    if (flag) continue;
    long long count = 0;
    cout << "Yes" << endl;
    vector<pair<long long, long long>> v;
    for (i = 0; i < n - 1; i++) {
      if (s[i] != t[i]) {
        for (j = i + 1; j < n; j++) {
          if (s[j] == s[i]) {
            s[j] = t[i];
            t[i] = s[i];
            count++;
            v.push_back(make_pair(j + 1, i + 1));
            break;
          }
        }
      }
      if (s[i] != t[i]) {
        for (j = i + 1; j < n; j++) {
          if (t[j] == s[i]) {
            t[j] = s[j];
            s[j] = s[i];
            v.push_back(make_pair(j + 1, j + 1));
            s[j] = t[i];
            t[i] = s[i];
            v.push_back(make_pair(j + 1, i + 1));
            count += 2;
            break;
          }
        }
      }
    }
    cout << count << endl;
    for (i = 0; i < count; i++)
      cout << v[i].first << " " << v[i].second << endl;
  }
  return 0;
}
