#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : -x;
}
const int N = 1e5 + 4, M = 24, S = 1 << 20;
int n, ans, to[M][M], vis[M], ban[M], f[S];
char s1[N], s2[N];
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < 20; i++)
    if ((to[i][x] || to[x][i]) && !vis[i]) dfs(i);
}
inline void solve() {
  memset(to, 0, sizeof(to));
  memset(vis, 0, sizeof(vis));
  memset(f, 0, sizeof(f));
  memset(ban, 0, sizeof(ban));
  ans = 0;
  n = read();
  scanf("%s%s", s1 + 1, s2 + 1);
  for (int i = 1; i <= n; i++) {
    if (s1[i] != s2[i]) to[s1[i] - 'a'][s2[i] - 'a'] = 1;
  }
  for (int i = 0; i < 20; i++) {
    f[1 << i] = 1;
    for (int j = 0; j < 20; j++)
      if (to[i][j]) ban[i] |= 1 << j;
  }
  for (int s = 1, bit; s < S; s++)
    if (f[s]) {
      bit = 0;
      for (int i = 0; i < 20; i++)
        if ((s >> i) & 1) bit++;
      ans = max(ans, bit);
      for (int i = 0; i < 20; i++)
        if (!((s >> i) & 1) && !(ban[i] & s)) {
          f[s | (1 << i)] = 1;
        }
    }
  ans = 40 - ans;
  for (int i = 0; i < 20; i++)
    if (!vis[i]) {
      ans--;
      dfs(i);
    }
  cout << ans << "\n";
}
int main() {
  for (int T = read(); T--;) solve();
  return (0 - 0);
}
