#include <bits/stdc++.h>
using namespace std;
char s[100010], t[100010];
int n, T;
bool f[22][22];
bool g[22][22];
bool vis[22];
int st[22], num;
void bfs(int a) {
  num = 0;
  queue<int> q;
  q.push(a);
  vis[a] = 1;
  while (!q.empty()) {
    int u = q.front();
    st[++num] = u;
    q.pop();
    for (int i = 0; i < 20; i++)
      if (g[u][i] && !vis[i]) {
        q.push(i);
        vis[i] = 1;
      }
  }
}
bool F[1100000];
int Suo[22];
int solve() {
  int maxn = (1 << num) - 1;
  for (int i = 0; i <= maxn; i++) F[i] = 0;
  for (int i = 1; i <= num; i++) F[1 << (i - 1)] = 1;
  int Max = 1;
  for (int i = 1; i <= maxn; i++)
    if (!F[i]) {
      int Sta = 0;
      int cnt = 0;
      for (int j = 1; j <= num; j++)
        if (i & (1 << (j - 1))) Sta |= 1 << st[j], cnt++;
      for (int j = 1; j <= num; j++)
        if (i & (1 << (j - 1))) {
          int G = Sta ^ (1 << st[j]);
          if (!(G & Suo[st[j]]) && F[i ^ (1 << (j - 1))])
            F[i] = 1, Max = max(Max, cnt);
        }
    }
  return (num << 1) - 1 - Max;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    memset(f, 0, sizeof(f));
    memset(vis, 0, sizeof(vis));
    memset(g, 0, sizeof(g));
    memset(Suo, 0, sizeof(Suo));
    scanf("%d%s%s", &n, &s[1], &t[1]);
    for (int i = 1; i <= n; i++)
      f[s[i] - 'a'][t[i] - 'a'] = 1,
                           g[s[i] - 'a'][t[i] - 'a'] =
                               g[t[i] - 'a'][s[i] - 'a'] = 1,
                           Suo[t[i] - 'a'] |= 1 << (s[i] - 'a');
    int ans = 0;
    for (int i = 0; i < 20; i++)
      if (!vis[i]) {
        bfs(i);
        ans += solve();
      }
    cout << ans << '\n';
  }
  return 0;
}
