#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
char A[MAXN], B[MAXN];
int n;
int G[21];
int fa[21];
inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
inline void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  fa[x] = y;
}
bool ps[21];
bool g[(1 << 20) + 3];
inline void Solve() {
  scanf("%d", &n);
  scanf("%s", A + 1);
  scanf("%s", B + 1);
  for (int i = 1; i <= 20; ++i) fa[i] = i;
  memset(G, 0, sizeof(G));
  memset(ps, 0, sizeof(ps));
  for (int i = 1; i <= n; ++i)
    G[A[i] - 'a'] |= 1 << (B[i] - 'a'), merge(A[i] - 'a' + 1, B[i] - 'a' + 1);
  for (int i = 1; i <= 20; ++i) ps[find(i)] = 1;
  int ans = 2 * 20;
  for (int i = 1; i <= 20; ++i) ans -= ps[i];
  int mx = 0;
  memset(g, 0, sizeof(g));
  g[0] = 1;
  for (int S = 0; S <= (1 << 20) - 1; ++S) {
    if (!g[S]) continue;
    mx = std::max(mx, __builtin_popcount(S));
    for (int i = 0; i <= 19; ++i) {
      if ((S >> i) & 1) continue;
      if (G[i] & S) continue;
      g[S | (1 << i)] = 1;
    }
  }
  ans -= mx;
  printf("%d\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) Solve();
  return 0;
}
