#include <bits/stdc++.h>
using namespace std;
char s[101010], t[101010];
bool d[1 << 20];
int f[22], to[22];
int getf(int x) {
  if (f[x] == x) return x;
  return (f[x] = getf(f[x]));
}
inline void work() {
  int n;
  scanf("%d%s%s", &n, s + 1, t + 1);
  memset(d, 0, sizeof(d));
  for (int i = 0; i < 20; i++) f[i] = i, to[i] = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] != t[i]) {
      to[s[i] - 'a'] |= 1 << (t[i] - 'a');
      int a = getf(s[i] - 'a'), b = getf(t[i] - 'a');
      f[a] = b;
    }
  }
  int ans = 40, p = 0;
  d[0] = true;
  for (int i = 0; i < (1 << 20); i++) {
    if (!d[i]) continue;
    p = max(p, __builtin_popcount(i));
    for (int j = 0; j < 20; j++) {
      if (to[j] & i) continue;
      d[i | (1 << j)] = 1;
    }
  }
  for (int i = 0; i < 20; i++) ans -= (getf(i) == i);
  printf("%d\n", ans - p);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    work();
  }
}
