#include <bits/stdc++.h>
using namespace std;
int i, j, m, xx, tst, n, ans[1050005], pick[22], inf;
bool connected[22][22], visit[22];
char s[100005], t[100005];
bool dfs1(int u, int uu) {
  int i;
  bool flag = false;
  visit[u] = true;
  for (i = 0; i <= n - 1; i++) {
    if ((pick[i]) && (connected[u][i]) && (i != u)) {
      if (i == uu) {
        return true;
      } else {
        if (!visit[i]) {
          flag = dfs1(i, uu);
          if (flag) return true;
        }
      }
    }
  }
  return false;
}
bool in_cycle(int u) {
  memset(visit, false, sizeof(visit));
  return dfs1(u, u);
}
void dfs2(int u) {
  int i;
  visit[u] = true;
  for (i = 0; i <= n - 1; i++) {
    if ((!visit[i]) && (pick[i]) && (connected[u][i] || connected[i][u])) {
      dfs2(i);
    }
  }
}
void solve(int u) {
  bool find_cycle = false;
  int i, j;
  for (i = 0; i <= n - 1; i++) {
    if ((pick[i]) && (in_cycle(i))) {
      find_cycle = true;
      if (ans[u - (1 << i)] == inf) {
        pick[i] = false;
        solve(u - (1 << i));
        pick[i] = true;
      }
      if (ans[u - (1 << i)] + 2 < ans[u]) ans[u] = ans[u - (1 << i)] + 2;
    }
  }
  if (!find_cycle) {
    int sz = 0;
    int cpn = 0;
    for (i = 0; i <= n - 1; i++) {
      if (pick[i]) sz++;
    }
    ans[u] = sz;
  }
}
void outputgraph() {
  int i, j;
  for (i = 0; i <= n - 1; i++) {
    for (j = 0; j <= n - 1; j++) {
      printf("%d ", connected[i][j]);
    }
    printf("\n");
  }
}
int main() {
  n = 20;
  inf = 1000000000;
  scanf("%d", &tst);
  while (tst--) {
    scanf("%d", &xx);
    scanf("%s", s);
    scanf("%s", t);
    memset(connected, false, sizeof(connected));
    for (i = 0; i <= xx - 1; i++) {
      connected[s[i] - 'a'][t[i] - 'a'] = true;
    }
    for (i = 0; i < (1 << n); i++) {
      ans[i] = inf;
    }
    for (i = 0; i <= n - 1; i++) {
      pick[i] = true;
    }
    ans[0] = 0;
    solve((1 << n) - 1);
    int cpn = 0;
    memset(visit, false, sizeof(visit));
    for (i = 0; i <= n - 1; i++) {
      if ((!visit[i]) && (pick[i])) {
        dfs2(i);
        cpn++;
      }
    }
    printf("%d\n", ans[(1 << n) - 1] - cpn);
  }
  return 0;
}
