#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5 + 5;
int N;
char A[MN], B[MN];
bool dag[1 << 20];
int to[25], fa[25];
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%s%s", &N, A + 1, B + 1);
    for (int i = 1; i <= 20; ++i) fa[i] = i, to[i] = 0;
    for (int i = 1; i <= N; ++i) {
      int a = A[i] - 'a' + 1, b = B[i] - 'a' + 1;
      fa[find(a)] = find(b);
      if (a != b) to[a] |= 1 << b - 1;
    }
    int tot = 40, ans = 0;
    for (int i = 1; i <= 20; ++i) tot -= (i == fa[i]);
    memset(dag, false, sizeof(dag));
    dag[0] = 1;
    for (int s = 0; s < (1 << 20); ++s)
      if (dag[s]) {
        for (int i = 0; i < 20; ++i)
          if (!(s >> i & 1) && ((s & to[i + 1]) == 0)) dag[s | 1 << i] = true;
        ans = max(ans, __builtin_popcount(s));
      }
    printf("%d\n", tot - ans);
  }
  return 0;
}
