#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int T, n, e[25], vis[25], ans, dp[(1 << 20) + 10], cnt[(1 << 20) + 10];
char a[100010], b[100010];
inline void dfs(const int& x) {
  vis[x] = T + 1;
  for (int i = 0; i < 20; ++i)
    if (vis[i] != T + 1 && ((e[x] & (1 << i)) || (e[i] & (1 << x)))) dfs(i);
}
int main() {
  for (int i = 1; i < (1 << 20); ++i) cnt[i] = cnt[i >> 1] + (i & 1);
  T = read();
  while (T--) {
    n = read();
    scanf("%s%s", a + 1, b + 1);
    ans = 0;
    for (int i = 0; i < 20; ++i) e[i] = 0;
    for (int i = 1; i <= n; ++i) e[a[i] - 'a'] |= (1 << b[i] - 'a');
    dp[0] = 1;
    for (int i = 1; i < (1 << 20); ++i) {
      dp[i] = 0;
      for (int j = 0; j < 20; ++j)
        if (i & (1 << j)) dp[i] |= (dp[i - (1 << j)] && !(e[j] & i - (1 << j)));
      if (dp[i]) ans = max(ans, cnt[i]);
    }
    ans = 40 - ans;
    for (int i = 0; i < 20; ++i)
      if (vis[i] != T + 1) {
        dfs(i);
        --ans;
      }
    printf("%d\n", ans);
  }
  return 0;
}
