#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, n, i, j, flag;
  string s, t;
  cin >> k;
  while (k--) {
    cin >> n >> s >> t;
    vector<pair<int, int> > v;
    for (i = 0; i < n; i++) {
      flag = 0;
      if (s[i] != t[i]) {
        j = i + 1;
        while (j < n) {
          if (s[i] == s[j]) {
            flag = 1;
            break;
          }
          j++;
        }
        if (flag == 1) {
          v.push_back(make_pair(j, i));
          swap(s[j], t[i]);
        } else if (flag == 0) {
          j = i + 1;
          while (j < n) {
            if (s[i] == t[j]) {
              flag = 1;
              break;
            }
            j++;
          }
          if (flag == 1) {
            v.push_back(make_pair(j, j));
            swap(t[j], s[j]);
            i--;
          }
        }
        if (flag == 0) break;
      }
    }
    if (s == t) {
      cout << "Yes\n" << v.size() << '\n';
      for (i = 0; i < v.size(); i++)
        cout << v[i].first + 1 << ' ' << v[i].second + 1 << '\n';
    } else
      cout << "No\n";
  }
}
