#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mex = 1e5 + 1;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, freq[26] = {0};
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    for (int i = 0; i < s1.size(); i++) {
      freq[s1[i] - 'a']++;
      freq[s2[i] - 'a']++;
    }
    int fg = 0;
    for (int i = 0; i < 26; i++)
      if (freq[i] & 1) fg = 1;
    vector<pair<int, int> > v;
    if (fg == 0) {
      for (int i = 0; i < s1.size(); i++) {
        if (s1[i] != s2[i]) {
          int id = 1;
          for (int j = i + 1; j < s1.size(); j++) {
            if (s1[i] == s1[j]) {
              swap(s1[j], s2[i]);
              v.push_back({j, i});
              id = 0;
              break;
            }
          }
          if (id) {
            for (int j = i + 1; j < s1.size(); j++) {
              if (s1[i] == s2[j]) {
                swap(s1[j], s2[j]);
                v.push_back({j, j});
                swap(s1[j], s2[i]);
                v.push_back({j, i});
                break;
              }
            }
          }
        }
      }
      cout << "YES" << endl;
      cout << v.size() << endl;
      for (int i = 0; i < v.size(); i++)
        cout << v[i].first + 1 << " " << v[i].second + 1 << endl;
    } else
      cout << "NO" << endl;
  }
}
