#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  while (k--) {
    int n;
    cin >> n;
    char srr[n + 1];
    char trr[n + 1];
    cin >> srr >> trr;
    int freq[26] = {0};
    for (int i = 0; i < n; i++) {
      freq[srr[i] - 'a']++;
      freq[trr[i] - 'a']++;
    }
    int flag = 0;
    for (int i : freq) {
      if (i % 2 != 0) {
        flag = 1;
      }
    }
    if (flag == 1)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      int ans[2][2 * n];
      int times = 0;
      for (int i = 0; i < n; i++) {
        if (srr[i] != trr[i]) {
          for (int j = i + 1; j < n; j++) {
            if (srr[j] == srr[i]) {
              char temp = trr[i];
              trr[i] = srr[j];
              srr[j] = temp;
              ans[0][times] = j + 1;
              ans[1][times] = i + 1;
              times++;
              break;
            } else if (trr[j] == srr[i]) {
              char temp = trr[j];
              trr[j] = srr[j];
              srr[j] = temp;
              ans[0][times] = j + 1;
              ans[1][times] = j + 1;
              times++;
              temp = trr[i];
              trr[i] = srr[j];
              srr[j] = temp;
              ans[0][times] = j + 1;
              ans[1][times] = i + 1;
              times++;
              break;
            }
          }
        }
      }
      cout << times << endl;
      for (int m = 0; m < times; m++) {
        cout << ans[0][m] << " " << ans[1][m] << endl;
      }
    }
  }
  return 0;
}
