#include <bits/stdc++.h>
using namespace std;
template <class T>
int check_mod(T a, T b) {
  return (a % b) ? 1 : 0;
}
template <class T>
void maxi(T &a, T b) {
  a = max(a, b);
  return;
}
template <class T>
void mini(T &a, T b) {
  a = min(a, b);
  return;
}
void sieve(vector<char> &prime, int range) {
  prime.resize(range + 1, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i <= range; i++)
    if (prime[i])
      for (int j = (i << 1); j <= range; j += i) prime[j] = 0;
  return;
}
void sieve(vector<char> &prime, vector<int> &prime_list, int range) {
  prime.resize(range + 1, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i <= range; i++)
    if (prime[i]) {
      prime_list.push_back(i);
      for (int j = (i << 1); j <= range; j += i) prime[j] = 0;
    }
  return;
}
void sieve(vector<char> &prime, vector<long long> &prime_list, int range) {
  prime.resize(range + 1, 1);
  prime[0] = prime[1] = 0;
  for (long long i = 2; i * i <= range; i++)
    if (prime[i]) {
      prime_list.push_back(i);
      for (long long j = (i << 1); j <= (long long)range; j += i) prime[j] = 0;
    }
  return;
}
bool is_letter(char a) {
  if (('a' <= a && a <= 'z') || ('A' <= a && a <= 'Z')) return true;
  return false;
}
bool is_vowel(char a) {
  string vowels = "aeiouyAEIOUY";
  for (char c : vowels)
    if (c == a) return true;
  return false;
}
bool is_valid(int i, int j, int N, int M) {
  return 0 <= i && i < N && 0 <= j && j < M;
}
bool all_adjacents_valid(int i, int j, int N, int M) {
  for (int di = -1; di <= 1; di++)
    for (int dj = -1; dj <= 1; dj++)
      if (((di) * (di)) + ((dj) * (dj)) == 1 && !is_valid(i + di, j + dj, N, M))
        return false;
  return true;
}
bool is_prime(int a) {
  if (a == 2) return true;
  if (!(a & 1) || a == 1) return false;
  for (int i = 3; i * i <= a; i += 2)
    if (!(a % i)) return false;
  return true;
}
bool is_prime(long long a) {
  if (a == 2) return true;
  if (!(a & 1) || a == 1) return false;
  for (long long i = 3; i * i <= a; i += 2)
    if (!(a % i)) return false;
  return true;
}
bool is_palindrome(string s) {
  int len = (int)s.length();
  int mid = len >> 1;
  for (int i = 0; i < mid; i++)
    if (s[i] != s[len - i - 1]) return false;
  return true;
}
bool is_palindrome(vector<char> s) {
  int len = (int)s.size();
  int mid = len >> 1;
  for (int i = 0; i < mid; i++)
    if (s[i] != s[len - i - 1]) return false;
  return true;
}
int gcd(int a, int b) {
  while (b) {
    int mod = a % b;
    a = b;
    b = mod;
  }
  return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int binpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}
int binpow(int a, int b, int MODULO) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      res %= MODULO;
    }
    a *= a;
    a %= MODULO;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    long long mod = a % b;
    a = b;
    b = mod;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}
long long binpow(long long a, long long b, long long MODULO) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      res %= MODULO;
    }
    a *= a;
    a %= MODULO;
    b >>= 1;
  }
  return res;
}
double distance(int X1, int Y1, int X2, int Y2) {
  return sqrt(((X1 - X2) * (X1 - X2)) + ((Y1 - Y2) * (Y1 - Y2)));
}
double distance(long long X1, long long Y1, long long X2, long long Y2) {
  return sqrt(((X1 - X2) * (X1 - X2)) + ((Y1 - Y2) * (Y1 - Y2)));
}
double distance(double X1, double Y1, double X2, double Y2) {
  return sqrt(((X1 - X2) * (X1 - X2)) + ((Y1 - Y2) * (Y1 - Y2)));
}
string binary(int N) {
  if (!N) return "0";
  string bin = "";
  while (N) {
    bin += '0' + (N & 1);
    N >>= 1;
  }
  reverse((bin).begin(), (bin).end());
  return bin;
}
string binary(long long N) {
  if (!N) return "0";
  string bin = "";
  while (N) {
    bin += '0' + (N & 1);
    N >>= 1;
  }
  reverse((bin).begin(), (bin).end());
  return bin;
}
vector<char> binary_v(int N) {
  if (!N) return {'0'};
  vector<char> bin;
  while (N) {
    bin.push_back('0' + (N & 1));
    N >>= 1;
  }
  reverse((bin).begin(), (bin).end());
  return bin;
}
vector<char> binary_v(long long N) {
  if (!N) return {'0'};
  vector<char> bin;
  while (N) {
    bin.push_back('0' + (N & 1));
    N >>= 1;
  }
  reverse((bin).begin(), (bin).end());
  return bin;
}
const int INF = 2147483547;
const int MODULO = 1000000007;
const int _MODULO = 998244353;
const long long INF64 = 9223372036854775707;
const long long MODULO64 = 1000000007;
const long long _MODULO64 = 998244353;
const double epsilon = 10e-6;
const double PI = acos(-1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int> bucket(26, 0);
    for (char c : s) ++bucket[c - 'a'];
    for (char c : t) ++bucket[c - 'a'];
    bool ok = true;
    for (int p : bucket) ok &= !(p & 1);
    if (!ok) {
      cout << "NO" << '\n';
      continue;
    }
    cout << "YES" << '\n';
    vector<pair<int, int>> ans;
    for (int i = 0; i < n; ++i) {
      if (s[i] == t[i]) continue;
      bool found = false;
      for (int j = i + 1; j < n && !found; ++j)
        if (t[j] == t[i]) {
          found = true;
          swap(s[i], t[j]);
          ans.emplace_back(i + 1, j + 1);
        }
      if (found) continue;
      for (int j = i + 1; j < n && !found; ++j)
        if (s[j] == t[i]) {
          found = true;
          swap(s[j], t[n - 1]);
          ans.emplace_back(j + 1, n);
          swap(s[i], t[n - 1]);
          ans.emplace_back(i + 1, n);
        }
    }
    cout << (int)ans.size() << '\n';
    for (auto p : ans) cout << p.first << " " << p.second << '\n';
  }
  return 0;
}
