#include <bits/stdc++.h>
using namespace std;
const long long INF = LONG_LONG_MAX;
const long long NINF = LONG_LONG_MIN;
const long long mmod = 1000000007;
int32_t main() {
  long long k;
  cin >> k;
  while (k-- > 0) {
    long long n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<long long> cnt(26, 0);
    for (long long i = 0; i < n; i++) {
      cnt[s[i] - 'a']++;
      cnt[t[i] - 'a']++;
    }
    bool found = true;
    for (long long i = 0; i < 26; i++)
      if (cnt[i] & 1) found = false;
    if (found) {
      vector<pair<long long, long long>> ans;
      for (long long i = 0; i < n - 1; i++) {
        if (s[i] != t[i]) {
          bool f = false;
          for (long long j = i + 1; j < n; j++) {
            if (t[j] == t[i]) {
              swap(s[i], t[j]);
              f = true;
              ans.emplace_back(i + 1, j + 1);
              break;
            }
          }
          if (!f) {
            for (long long j = i + 1; j < n; j++) {
              if (s[j] == t[i]) {
                swap(s[j], t[j]);
                swap(s[i], t[j]);
                ans.emplace_back(j + 1, j + 1);
                ans.emplace_back(i + 1, j + 1);
                break;
              }
            }
          }
        }
      }
      cout << "YES" << endl;
      cout << (long long)ans.size() << endl;
      for (pair<long long, long long> x : ans)
        cout << x.first << ' ' << x.second << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
