#include <bits/stdc++.h>
using namespace std;
const long long MXN = 1e5 + 7;
const long long INF = 2e18 + 7;
inline void Need_for_speed() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int n, q, used[100];
string a, b;
bool ok(string a, string b) {
  for (int i = 0; i < a.size(); i++) {
    used[a[i] - 97]++;
    used[b[i] - 97]++;
  }
  for (int i = 0; i < 26; i++) {
    if (used[i] % 2 != 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  Need_for_speed();
  cin >> q;
  while (q--) {
    vector<pair<int, int> > node;
    bool flag = 1;
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (b[j] == b[i] && a[i] == a[j] && i != j && a[i] != b[j]) {
          swap(b[j], a[i]);
          node.push_back({i + 1, j + 1});
        } else if (a[i] == a[j] && i != j && a[j] != b[j] && a[i] != b[i]) {
          swap(a[i], b[j]);
          node.push_back({i + 1, j + 1});
        } else if (b[i] == b[j] && i != j && a[j] != b[j] && a[i] != b[i]) {
          swap(b[i], a[j]);
          node.push_back({j + 1, i + 1});
        }
      }
    }
    if (!ok(a, b)) flag = 0;
    if (flag) {
      for (int i = 0; i < n && a != b; i++) {
        if (a[i] != b[i]) {
          swap(a[i], b[i]);
          node.push_back({i + 1, i + 1});
          for (int j = 0; j < n; j++) {
            if (a[i] == a[j] && i != j && b[i] == b[j]) {
              swap(a[i], b[j]);
              node.push_back({i + 1, j + 1});
            }
          }
          if (a[i] != b[i]) {
            for (int j = 0; j < n; j++) {
              if (a[i] == a[j] && i != j && a[j] != b[j]) {
                swap(a[j], b[i]);
                node.push_back({j + 1, i + 1});
                i = 0;
              }
            }
            for (int j = 0; j < n; j++) {
              if (b[i] == b[j] && i != j && a[j] != b[j]) {
                swap(b[j], a[i]);
                node.push_back({i + 1, j + 1});
                i = 0;
              }
            }
          }
        }
      }
      cout << "Yes" << endl << node.size() << endl;
      for (pair<int, int> i : node) {
        cout << i.first << ' ' << i.second << endl;
      }
    } else {
      cout << "No" << endl;
    }
    fill(used, used + 27, 0);
  }
}
