#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = (1 << 20) + 5;
char s1[N], s2[N];
int a[N], b[N], f[M], d[25], c[M];
bool v[25], mp[25][25];
vector<int> G[25];
void dfs(int x) {
  v[x] = 1;
  for (unsigned int i = 0; i < G[x].size(); i++)
    if (!v[G[x][i]]) dfs(G[x][i]);
}
int main() {
  int t;
  scanf("%d", &t);
  for (int i = 1; i < (1 << 20); i++) c[i] = c[i >> 1] + (i & 1);
  while (t--) {
    memset(mp, 0, sizeof(mp));
    memset(v, 0, sizeof(v));
    int n;
    scanf("%d%s%s", &n, s1 + 1, s2 + 1);
    for (int i = 1; i <= n; i++) a[i] = s1[i] - 'a', b[i] = s2[i] - 'a';
    for (int i = 0; i < 20; i++) G[i].clear(), d[i] = 0;
    for (int i = 1; i <= n; i++)
      if (a[i] != b[i] && !mp[a[i]][b[i]]) {
        d[a[i]] |= 1 << b[i];
        mp[a[i]][b[i]] = 1;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
      }
    int cnt = 0;
    for (int i = 0; i < 20; i++)
      if (!v[i]) ++cnt, dfs(i);
    int ans = 0;
    memset(f, 0, sizeof(f));
    f[0] = 1;
    for (int i = 0; i < (1 << 20); i++)
      if (f[i]) {
        ans = max(ans, c[i]);
        for (int j = 0; j < 20; j++)
          if ((~i >> j & 1) && ((d[j] & i) == 0)) f[i | (1 << j)] = 1;
      }
    printf("%d\n", 2 * 20 - cnt - ans);
  }
  return 0;
}
