#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-15, pi = 3.1415926535897932385;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}, inf = 0x7fffffff;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f = ('-' == ch ? -1 : 1), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  if (~f) return x;
  return -x;
}
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
inline void ad(int &x, int y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
}
inline void su(int &x, int y) {
  x -= y;
  if (x < 0) x += 1000000007;
}
int Pow(int x, int y) {
  if (y < 0) return Pow(Pow(x, 1000000007 - 2), -y);
  int now = 1;
  for (; y; y >>= 1, x = 1LL * x * x % 1000000007)
    if (y & 1) now = 1LL * now * x % 1000000007;
  return now;
}
inline int ct(int x) {
  int sum = 0;
  for (int i = 0; i <= 31; i++) sum += 1 & (x >> i);
  return sum;
}
int vis[20], n, u[1 << 20], v[1 << 20], f[1 << 20];
char s[100005], t[100005];
vector<int> e[20];
int dfs(int x) {
  vis[x] = 1;
  int cur = 1 << x;
  for (auto y : e[x])
    if (!vis[y]) cur |= dfs(y);
  return cur;
}
void calc() {
  f[0] = 1;
  for (int i = 1; i <= (1 << 20) - 1; i++) {
    for (int j = 0; j <= 20 - 1; j++)
      if ((1 & (i >> j)) && !(u[1 << j] & i)) f[i] |= f[i ^ (1 << j)];
  }
}
void solve() {
  n = read();
  memset(vis, 0, sizeof(vis)), memset(u, 0, sizeof(u)), memset(v, 0, sizeof(v)),
      memset(f, 0, sizeof(f));
  for (int i = 0; i <= 19; i++) e[i].clear();
  scanf("%s%s", s + 1, t + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] != t[i]) {
      int x = s[i] - 'a';
      int y = t[i] - 'a';
      u[1 << x] |= 1 << y;
      v[1 << y] |= 1 << x;
      e[x].push_back(y);
      e[y].push_back(x);
    }
  calc();
  int ans = 20 * 2;
  for (int i = 0; i <= 19; i++)
    if (!vis[i]) {
      int cur = dfs(i);
      int mx = 0;
      for (int j = cur; j; j = cur & (j - 1))
        if (f[j]) mx = max(mx, ct(j));
      ans -= mx + 1;
    }
  printf("%d\n", ans);
}
int main() {
  int T = read();
  while (T--) solve();
  return 0;
}
