#include <bits/stdc++.h>
using namespace std;
const int maxn = 100009;
int g[20];
int n;
char s[maxn], t[maxn];
int f[1 << 20];
int father[maxn];
int find(int x) {
  if (x == father[x]) return x;
  return father[x] = find(father[x]);
}
void unionn(int x, int y) {
  x = find(x);
  y = find(y);
  if (x != y) father[x] = y;
}
int main() {
  int Tn;
  scanf("%d", &Tn);
  while (Tn--) {
    memset(f, 0, sizeof(f));
    memset(g, 0, sizeof(g));
    scanf("%d", &n);
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    for (int i = 0; i < 20; ++i) father[i] = i;
    for (int i = 1; i <= n; ++i) {
      if (s[i] != t[i]) {
        int x = s[i] - 'a';
        int y = t[i] - 'a';
        g[x] |= 1 << y;
        unionn(x, y);
      }
    }
    int cnt = 0;
    for (int i = 0; i < 20; ++i)
      if (father[i] == i) ++cnt;
    f[0] = 1;
    for (int s = 0; s < (1 << 20); ++s) {
      if (!f[s]) continue;
      for (int i = 0; i < 20; ++i) {
        if ((s >> i) & 1) continue;
        if (s & g[i]) continue;
        f[s | (1 << i)] = 1;
      }
    }
    int mx = 0;
    for (int s = 0; s < (1 << 20); ++s) {
      if (f[s]) mx = max(mx, __builtin_popcount(s));
    }
    printf("%d\n", 40 - mx - cnt);
  }
  return 0;
}
