#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  boost();
  long long int n, k, i, j, m;
  cin >> k;
  while (k--) {
    cin >> n;
    string s, t;
    cin >> s;
    cin >> t;
    long long int cnt[26];
    long long int flag = 0;
    memset(cnt, 0, sizeof(cnt));
    for (i = 0; i < s.size(); i++) {
      cnt[s[i] - 'a']++;
      cnt[t[i] - 'a']++;
    }
    for (i = 0; i < 26; i++) {
      if (cnt[i] % 2 == 1) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      cout << "No" << endl;
      continue;
    } else
      cout << "Yes" << endl;
    vector<pair<long long int, long long int> > ans;
    for (i = 0; i < n; ++i) {
      if (s[i] == t[i]) {
        continue;
      } else {
        long long int ok = 0;
        char temp;
        for (j = i + 1; j < n; ++j) {
          if (s[j] == s[i]) {
            ok = 1;
            temp = t[i];
            t[i] = s[j];
            s[j] = temp;
            ans.push_back({j + 1, i + 1});
            break;
          }
        }
        if (ok == 0) {
          for (j = i + 1; j < n; ++j) {
            if (t[j] == s[i]) {
              temp = t[j];
              t[j] = s[j];
              s[j] = temp;
              ans.push_back({j + 1, j + 1});
              temp = t[i];
              t[i] = s[j];
              s[j] = temp;
              ans.push_back({j + 1, i + 1});
              break;
            }
          }
        }
      }
    }
    cout << (long long int)ans.size() << endl;
    for (i = 0; i < (long long int)ans.size(); ++i) {
      cout << ans[i].first << " " << ans[i].second << endl;
    }
  }
  return 0;
}
