#include <bits/stdc++.h>
using namespace std;
int t, n, ans, maxn;
int cnt[100010 * 20], to[22], fa[22];
bool f[100010 * 20];
char a[100010], b[100010];
int find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  for (int i = 0; i < (1 << 20); i++) cnt[i] = cnt[i >> 1] + (i & 1);
  scanf("%d", &t);
  while (t--) {
    memset(f, false, sizeof(f));
    memset(to, 0, sizeof(to));
    maxn = 0;
    ans = 40;
    scanf("%d\n%s%s", &n, a, b);
    for (int i = 0; i < 20; i++) fa[i] = i;
    for (int i = 0; i < n; i++) {
      if (a[i] == b[i]) continue;
      int x = a[i] - 'a', y = b[i] - 'a';
      to[x] |= (1 << y);
      int fx = find(x), fy = find(y);
      fa[fx] = fy;
    }
    for (int i = 0; i < 20; i++)
      if (fa[i] == i) ans--;
    f[0] = 1;
    for (int s = 0; s < (1 << 20); s++) {
      if (!f[s]) continue;
      maxn = max(maxn, cnt[s]);
      for (int i = 0; i < 20; i++) {
        int state = (1 << i);
        if (s & to[i]) continue;
        f[s | state] = 1;
      }
    }
    printf("%d\n", ans - maxn);
  }
  return 0;
}
