#include <bits/stdc++.h>
using namespace std;
int T, n, w[25][25], sumv[(1 << 21)], dp[(1 << 21)], maxv = (1 << 20) - 1;
char Ai[100050], Bi[100500];
int fuc[59];
inline void Ckmin(int& x, int y) {
  if (x == -1)
    x = y;
  else
    x = min(x, y);
}
bool check(int s, int i) {
  return ((!(sumv[s] & (s ^ maxv))) && (!(sumv[s ^ maxv] & s)));
}
int main() {
  scanf("%d", &T);
  for (int id = 1; id <= T; id++) {
    scanf("%d%s%s", &n, Ai, Bi);
    memset(w, 0, sizeof(w));
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++)
      if (Ai[i] != Bi[i]) w[Ai[i] - 'a'][Bi[i] - 'a'] = 1;
    for (int a = 0; a < 20; a++) {
      sumv[(1 << a)] = 0;
      for (int b = 0; b < 20; b++)
        if (w[a][b]) sumv[(1 << a)] |= (1 << b);
    }
    for (int s = 1; s < (1 << 20); s++)
      sumv[s] = (sumv[s ^ (s & -s)] | sumv[(s & -s)]);
    dp[0] = 0;
    for (int s = 0; s < (1 << 20); s++) {
      for (int i = 0; i < 20; i++)
        if (!(s & (1 << i))) {
          if (check(s, i))
            Ckmin(dp[s | (1 << i)], dp[s] + ((sumv[s] >> i) & 1));
          else
            Ckmin(dp[s | (1 << i)], dp[s] + ((sumv[s] >> i) & 1) + 1);
        }
    }
    printf("%d\n", dp[(1 << 20) - 1]);
  }
  return 0;
}
