#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int maxm = 25;
char a[maxn], b[maxn];
int fa[maxm], to[maxm];
bool dp[1 << 20];
inline int find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
void merge(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;
  fa[u] = v;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    cin >> a + 1 >> b + 1;
    for (int i = 0; i < 20; i++) fa[i] = i, to[i] = 0;
    for (int i = 1; i <= n; i++) {
      int u = a[i] - 'a', v = b[i] - 'a';
      to[u] |= (1 << v);
      merge(u, v);
    }
    int ans = 40;
    for (int i = 0; i < 20; i++)
      if (find(i) == i) ans--;
    memset(dp, false, sizeof dp);
    dp[0] = true;
    int max_ = 0;
    for (int s = 0; s < (1 << 20); s++)
      if (dp[s]) {
        int cur = 0;
        for (int i = 0; i < 20; i++) {
          int temp = 1 << i;
          if (temp & s) cur++;
          if (to[i] & s) continue;
          dp[s | temp] = true;
        }
        max_ = max(max_, cur);
      }
    cout << ans - max_ << '\n';
  }
  return 0;
}
