#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
inline int NofDigit(long long int N) { return floor(log10(N)) + 1; }
inline bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void print(int* a, int n) {
  int i;
  for (i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
int maxx = 1000005;
int a[1000005] = {0};
vector<long long int> sieve() {
  vector<long long int> v;
  long long int i;
  for (i = 2; i < maxx; i++) {
    if (a[i] > 0) continue;
    a[i] = 1;
    long long j = i * i;
    while (j < maxx) {
      if (a[j] == 0) a[j] = i;
      j += i;
    }
    v.push_back(i);
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int a[26] = {0};
    int i;
    for (i = 0; i < s.size(); i++) {
      a[s[i] - 'a']++;
      a[t[i] - 'a']++;
    }
    int flag = 0;
    for (i = 0; i < 26; i++) {
      if (a[i] & 1) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      cout << "NO" << endl;
      continue;
    }
    i = 0;
    vector<pair<int, int> > v;
    while (i < s.size()) {
      if (s[i] == t[i]) {
        i++;
        continue;
      }
      int j;
      flag = 0;
      for (j = i + 1; j < n; j++) {
        if (s[i] == s[j]) {
          v.push_back({j + 1, i + 1});
          swap(s[j], t[i]);
          flag = 1;
          break;
        }
      }
      if (!flag) {
        for (j = i + 1; j < n; j++) {
          if (t[j] == s[i]) {
            v.push_back({i + 2, j + 1});
            swap(s[i + 1], t[j]);
            v.push_back({i + 2, i + 1});
            swap(s[i + 1], t[i]);
            flag = 1;
            break;
          }
        }
      }
      if (!flag) {
        break;
      }
      i++;
    }
    if (!flag) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    cout << v.size() << endl;
    for (i = 0; i < v.size(); i++) {
      cout << v[i].first << " " << v[i].second << endl;
    }
  }
}
