#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int t, n, f[25], to[25], dp[1200005];
char s[100005], b[100005];
int getf(int x) { return x == f[x] ? x : f[x] = getf(f[x]); }
bool vis[21];
int main() {
  int i, j, f1, f2;
  t = read();
  while (t--) {
    n = read();
    scanf("%s", s + 1);
    scanf("%s", b + 1);
    for (i = 0; i <= 20; i++) f[i] = i, vis[i] = 0, to[i] = 0;
    for (i = 1; i <= n; i++) {
      to[s[i] - 'a'] |= 1 << (b[i] - 'a');
      vis[s[i] - 'a'] = 1, vis[b[i] - 'a'] = 1;
      f1 = getf(s[i] - 'a'), f2 = getf(b[i] - 'a');
      if (f1 == f2) continue;
      f[f1] = f2;
    }
    int cnt = 0, mn = 0;
    for (i = 0; i < 20; i++)
      if (vis[i] && getf(i) == i) mn--;
    for (i = 0; i < 20; i++)
      if (!vis[i]) cnt++;
    int mx = 0;
    for (i = 0; i < (1 << 20); i++) dp[i] = 0;
    dp[0] = 1;
    for (i = 0; i < (1 << 20); i++) {
      if (!dp[i]) continue;
      int bits = 0;
      for (j = 0; j < 20; j++) {
        if (i & (1 << j)) bits++;
        if (to[j] & i) continue;
        dp[i | (1 << j)] = true;
      }
      mx = max(bits, mx);
    }
    printf("%d\n", (20 - cnt) * 2 - mx + cnt + mn);
  }
}
