#include <bits/stdc++.h>
using namespace std;
char s1[100005], s2[100005];
int val[25];
bool vis[25];
int id[25], sz;
void dfs(int x) {
  vis[x] = 1;
  id[sz++] = x;
  for (int i = 0; i < 20; i++)
    if (!vis[i] && (val[x] & val[i])) dfs(i);
}
int f[1 << 20], bel[25];
int dp(int x) {
  sz = 0;
  dfs(x);
  int st = 0;
  for (int i = 0; i < sz; i++) {
    int x = id[i];
    st |= val[x];
    for (int j = 0; j < 20; j++)
      if ((val[x] >> j) & 1) bel[j] |= (1 << i);
  }
  memset(f, 0, sizeof(int) * (1 << sz));
  for (int i = 1; i < (1 << sz); i++)
    for (int j = 0; j < sz; j++)
      if ((i >> j) & 1)
        f[i] = max(f[i], f[i ^ (1 << j)] + ((bel[id[j]] & i) == bel[id[j]]));
  return __builtin_popcount(st) + sz - f[(1 << sz) - 1] - 1;
}
int main() {
  int cases;
  scanf("%d", &cases);
  for (; cases; cases--) {
    memset(bel, 0, sizeof(bel));
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < 20; i++) val[i] = (1 << i);
    int n;
    scanf("%d%s%s", &n, s1 + 1, s2 + 1);
    for (int i = 1; i <= n; i++)
      if (s1[i] != s2[i]) val[s1[i] - 'a'] |= (1 << (s2[i] - 'a'));
    int ans = 0;
    for (int i = 0; i < 20; i++)
      if (!vis[i]) ans += dp(i);
    printf("%d\n", ans);
  }
  return 0;
}
