#include <bits/stdc++.h>
using namespace std;
int freq[26];
int main() {
  int t;
  cin >> t;
  while (t--) {
    vector<pair<int, int> > pi;
    int n;
    cin >> n;
    memset(freq, 0, sizeof freq);
    string s1;
    string s2;
    cin >> s1 >> s2;
    for (int i = 0; i < n; i++) {
      freq[s1[i] - 97]++;
      freq[s2[i] - 97]++;
    }
    bool f = false;
    for (int i = 0; i < 26; i++) {
      if (freq[i] % 2 != 0) {
        f = true;
        break;
      }
    }
    if (f) {
      cout << "no" << endl;
      continue;
    }
    int c = 0;
    for (int i = 0; i < s1.size(); i++) {
      bool f1 = false;
      if (s1[i] != s2[i]) {
        for (int j = i + 1; j < n; j++)
          if (s1[i] == s1[j] && s1[j] != s2[j]) {
            swap(s2[i], s1[j]);
            pi.push_back({j, i});
            f1 = true;
            c++;
            break;
          }
        if (!f1) {
          for (int j = i + 1; j < n; j++)
            if (s1[i] == s2[j] && s1[j] != s2[j]) {
              swap(s1[j], s2[j]);
              pi.push_back({j, j});
              swap(s2[i], s1[j]);
              pi.push_back({j, i});
              c += 2;
              break;
            }
        }
      }
    }
    if (c <= 2 * n) {
      cout << "yes" << endl;
      cout << c << endl;
      for (int i = 0; i < pi.size(); i++)
        cout << pi[i].first + 1 << " " << pi[i].second + 1 << endl;
    } else
      cout << "no" << endl;
  }
}
