#include <bits/stdc++.h>
using namespace std;
char a[100002], b[100002];
int par[20], reach[20];
bool isDag[(1 << 20)];
void init() {
  for (int i = 0; i < 20; ++i) par[i] = i;
  memset(reach, 0, sizeof(reach));
  memset(isDag, false, sizeof(isDag));
}
int root(int x) {
  if (par[x] == x) return x;
  return par[x] = root(par[x]);
}
void Union(int x, int y) {
  x = root(x);
  y = root(y);
  if (x != y) par[x] = y;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d\n%s\n%s", &n, &a, &b);
    init();
    for (int i = 0; i < n; ++i)
      if (a[i] != b[i]) {
        reach[a[i] - 'a'] |= (1 << (b[i] - 'a'));
        Union(a[i] - 'a', b[i] - 'a');
      }
    int all = 1 << 20, LDAG = 0;
    isDag[0] = true;
    for (int config = 1; config < all; ++config) {
      int countB = 0;
      for (int j = 0; j < 20; ++j)
        if (config & (1 << j)) {
          ++countB;
          if (isDag[config ^ (1 << j)] &&
              ((reach[j] & (config ^ (1 << j))) == 0))
            isDag[config] = true;
        }
      if (isDag[config] && countB > LDAG) LDAG = countB;
    }
    int comp = 0;
    for (int i = 0; i < 20; ++i)
      if (root(i) == i) {
        ++comp;
      }
    printf("%d\n", 2 * 20 - LDAG - comp);
  }
  return 0;
}
