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