#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10, STA = (1 << 20) + 10;
int T, n;
char A[N], B[N];
int id[30], cnt;
int fa[30];
int to[30], f[STA], ans;
int find(int u) {
  if (fa[u] == u) return u;
  return fa[u] = find(fa[u]);
}
void merge(int x, int y) { fa[find(y)] = find(x); }
int lowbit(int x) { return x & -x; }
int calc(int x) {
  int ret = 0;
  while (x) x -= lowbit(x), ret++;
  return ret;
}
int block[30];
void Work() {
  scanf("%d", &n);
  scanf("%s", A + 1);
  scanf("%s", B + 1);
  for (int i = 0; i < 20; ++i) fa[i] = i;
  memset(to, 0, sizeof(to));
  cnt = 0;
  memset(id, -1, sizeof(id));
  for (int i = 1; i <= n; ++i) {
    int u = A[i] - 'a', v = B[i] - 'a';
    if (id[u] == -1) id[u] = cnt++;
    u = id[u];
    if (id[v] == -1) id[v] = cnt++;
    v = id[v];
    merge(u, v);
    to[u] |= (1 << v);
  }
  ans = 2 * cnt;
  for (int i = 0; i < cnt; ++i)
    if (find(i) == i) ans--;
  memset(f, 0, sizeof(f));
  f[0] = 1;
  int maxs = 0;
  for (int S = 0; S < (1 << cnt); ++S) {
    if (!f[S]) continue;
    maxs = max(maxs, calc(S));
    for (int i = 0; i < cnt; ++i) {
      if ((~S & (1 << i)) && !(S & to[i])) f[S | (1 << i)] = true;
    }
  }
  printf("%d\n", ans - maxs);
}
int main() {
  scanf("%d", &T);
  while (T--) Work();
  return 0;
}
