#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char A[maxn], B[maxn];
int f[30], to[30];
int findx(int x) { return f[x] == x ? x : f[x] = findx(f[x]); }
void unite(int x, int y) {
  x = findx(x);
  y = findx(y);
  if (x == y) return;
  f[x] = y;
}
bool dp[1 << 21];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    scanf("%s%s", A + 1, B + 1);
    for (int i = 0; i < 20; i++) f[i] = i, to[i] = 0;
    for (int i = 1; i <= n; i++) {
      int x = A[i] - 'a', y = B[i] - 'a';
      to[x] |= (1 << y);
      unite(x, y);
    }
    int ans = 40;
    for (int i = 0; i < 20; i++)
      if (findx(i) == i) ans--;
    memset(dp, false, sizeof(dp));
    dp[0] = true;
    int maxs = 0;
    for (int s = 0; s < (1 << 20); s++) {
      if (!dp[s]) continue;
      int cur = 0;
      for (int i = 0; i < 20; i++) {
        int tmp = 1 << i;
        if (tmp & s) cur++;
        if (to[i] & s) continue;
        dp[s | tmp] = true;
      }
      maxs = max(maxs, cur);
    }
    printf("%d\n", ans - maxs);
  }
  return 0;
}
