#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double pie = 3.14159265358979;
const long long mod = 1e9 + 7;
void solve(int test_case) {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int h[26] = {};
  for (auto i : s) h[i - 'a']++;
  for (auto i : t) h[i - 'a']++;
  int i = 0;
  for (; i < 26 && h[i] % 2 == 0; i++)
    ;
  if (i < 26) {
    cout << "No";
    cout << "\n";
    ;
    return;
  }
  cout << "Yes\n";
  vector<pair<int, int> > v;
  while (s != t) {
    int i = 0;
    for (; i < n && s[i] == t[i]; i++)
      ;
    int j = i + 1;
    for (; j < n && s[j] != s[i]; j++)
      ;
    if (j < n) {
      v.push_back(make_pair(j, i));
      swap(s[j], t[i]);
      continue;
      ;
    }
    j = i + 1;
    for (; j < n && t[j] != t[i]; j++)
      ;
    if (j < n) {
      v.push_back(make_pair(i, j));
      swap(s[i], t[j]);
      continue;
      ;
    }
    j = i + 1;
    for (; j < n && t[j] != s[i]; j++)
      ;
    v.push_back(make_pair(i + 1, j));
    swap(s[i + 1], t[j]);
    v.push_back(make_pair(i + 1, i));
    swap(s[i + 1], t[i]);
  }
  cout << v.size();
  cout << "\n";
  for (auto i : v) cout << i.first + 1 << " " << i.second + 1, cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  for (int i = 0; i < t; i++) solve(i);
  return 0;
}
