#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j;
  cin >> t;
  while (t--) {
    int n, a, b;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int count = 0;
    vector<pair<int, int>> v;
    int flag1 = 0;
    for (i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        int flag = 0;
        for (j = i + 1; j < n; j++) {
          if (t[j] == t[i]) {
            flag = 1;
            v.push_back({i, j});
            swap(s[i], t[j]);
            break;
          }
        }
        if (flag == 0) {
          for (j = i + 1; j < n; j++) {
            if (t[i] == s[j]) {
              flag = 1;
              v.push_back({j, j});
              swap(s[j], t[j]);
              v.push_back({i, j});
              swap(t[j], s[i]);
              break;
            }
          }
          if (flag == 0) {
            flag1 = 1;
            break;
          }
        }
      }
    }
    if (flag1 == 1 || v.size() > 2 * n) {
      cout << "NO\n";
    } else {
      cout << "YES\n" << v.size() << endl;
      for (i = 0; i < v.size(); i++) {
        cout << v[i].first + 1 << " " << v[i].second + 1 << endl;
      }
    }
  }
}
