#include <bits/stdc++.h>
using namespace std;
char s[109000], t[109000];
int n, reach[26], is_DAG[1 << 20], cnt, ans, e[26][26], book[26];
void dfs(int u) {
  book[u] = 1;
  for (int i = 0; i < 20; ++i)
    if (e[u][i] && book[i] == 0) dfs(i);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    scanf("%s%s", s + 1, t + 1);
    memset(e, 0, sizeof(e));
    memset(reach, 0, sizeof(reach));
    for (int i = 1; i <= n; ++i) {
      if (s[i] != t[i]) {
        int u = s[i] - 'a', v = t[i] - 'a';
        reach[u] |= 1 << v;
        e[u][v] = e[v][u] = 1;
      }
    }
    ans = cnt = 0;
    memset(book, 0, sizeof(book));
    for (int i = 0; i < 20; ++i) {
      if (!book[i]) {
        dfs(i);
        cnt++;
      }
    }
    is_DAG[0] = 1;
    for (int i = 1; i < (1 << 20); ++i) {
      is_DAG[i] = 0;
      for (int j = 0; j < 20; ++j) {
        if (i & (1 << j)) {
          is_DAG[i] |= is_DAG[i ^ (1 << j)] && ((reach[j] & i) == 0);
          if (is_DAG[i]) break;
        }
      }
      if (is_DAG[i]) ans = max(__builtin_popcount(i), ans);
    }
    printf("%d\n", 40 - cnt - ans);
  }
  return 0;
}
