#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 20;
int T, n, a[M], f[1 << M], cnt, ans, b[M][M], vis[M];
char S1[N], S2[N];
void adde(int u, int v) { b[u][v] = b[v][u] = 1; }
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < 20; ++i)
    if (b[u][i] && !vis[i]) dfs(i);
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%s%s", &n, S1, S2);
    for (int i = 0; i < 20; ++i) {
      a[i] = 0;
      for (int j = 0; j < 20; ++j) b[i][j] = 0;
    }
    for (int i = 0; i < n; ++i)
      if (S1[i] != S2[i]) {
        a[S1[i] - 'a'] |= 1 << (S2[i] - 'a');
        adde(S1[i] - 'a', S2[i] - 'a');
      }
    ans = cnt = 0;
    for (int i = 0; i < 20; ++i) vis[i] = 0;
    for (int i = 0; i < 20; ++i)
      if (!vis[i]) {
        cnt++;
        dfs(i);
      }
    f[0] = 1;
    for (int i = 1; i < (1 << 20); ++i) {
      f[i] = 0;
      for (int j = 0; j < 20; ++j)
        if (i & (1 << j)) {
          f[i] |= f[i ^ (1 << j)] && ((a[j] & i) == 0);
          if (f[i]) break;
        }
      if (f[i]) ans = max(__builtin_popcount(i), ans);
    }
    printf("%d\n", 40 - cnt - ans);
  }
  return 0;
}
