#include <bits/stdc++.h>
using namespace std;
long long test, cnt[26], n;
string s, t;
vector<pair<long long, long long> > vc;
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> test;
  while (test--) {
    cin >> n;
    cin >> s >> t;
    for (long long i = 0; i < 26; i++) cnt[i] = 0;
    for (long long i = 0; i < n; i++) cnt[s[i] - 'a']++;
    for (long long i = 0; i < n; i++) cnt[t[i] - 'a']++;
    bool ck = 0;
    for (long long i = 0; i < 26; i++) ck |= (cnt[i] % 2);
    if (ck) {
      cout << "No\n";
      continue;
    }
    cout << "Yes\n";
    for (long long i = 0; i < n; i++) {
      if (s[i] == t[i]) continue;
      for (long long j = i + 1; j < n; j++) {
        if (s[j] == s[i]) {
          vc.push_back({j + 1, i + 1});
          swap(s[j], t[i]);
          break;
        }
        if (s[j] == t[i]) {
          vc.push_back({j + 1, j + 1});
          swap(s[j], t[j]);
          vc.push_back({i + 1, j + 1});
          swap(s[i], t[j]);
          break;
        }
        if (t[i] == t[j]) {
          vc.push_back({i + 1, j + 1});
          swap(s[i], t[j]);
          break;
        }
        if (t[j] == s[i]) {
          vc.push_back({j + 1, j + 1});
          swap(s[j], t[j]);
          vc.push_back({j + 1, i + 1});
          swap(s[j], t[i]);
          break;
        }
      }
    }
    cout << vc.size() << "\n";
    for (long long i = 0; i < vc.size(); i++)
      cout << vc[i].first << " " << vc[i].second << "\n";
    vc.clear();
  }
}
