#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
void swap(char &a, char &b) {
  char c = a;
  a = b;
  b = c;
}
int main() {
  int q, n;
  cin >> q;
  string a, b;
  while (q--) {
    cin >> n;
    cin >> a >> b;
    a = '.' + a;
    b = '.' + b;
    int num1[27] = {0}, num2[27] = {0}, s = 0;
    ;
    for (int i = 1; i <= n; i++) {
      num1[a[i] - 'a']++;
      num2[b[i] - 'a']++;
    }
    for (int i = 0; i < 26; i++) {
      if ((num1[i] + num2[i]) % 2) {
        s = 1;
        break;
      }
    }
    if (s) {
      cout << "No" << endl;
      continue;
    }
    cout << "Yes" << endl;
    vector<pair<int, int> > ans;
    int w = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] != b[i]) {
        int f = 1;
        for (int j = i + 1; j <= n; j++) {
          if (b[j] == b[i]) {
            f = 0;
            w++;
            ans.push_back(make_pair(i, j));
            swap(a[i], b[j]);
            break;
          }
        }
        if (f) {
          for (int j = i + 1; j <= n; j++) {
            if (a[j] == b[i]) {
              w += 2;
              ans.push_back(make_pair(j, j));
              swap(a[j], b[j]);
              ans.push_back(make_pair(i, j));
              swap(a[i], b[j]);
              break;
            }
          }
        }
      }
    }
    cout << w << endl;
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i].first << ' ' << ans[i].second;
      cout << endl;
    }
  }
}
