#include <bits/stdc++.h>
const int SIG = 20, M = 1 << SIG;
int mp[SIG];
bool vis[SIG];
bool dp[M];
char s[100010], t[100010];
void dfs(const int &f) {
  vis[f] = true;
  for (int t = 0; t != SIG; ++t) {
    if (!vis[t] && ((mp[f] >> t & 1) || (mp[t] >> f & 1))) {
      dfs(t);
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    for (int i = 0; i != SIG; ++i) {
      mp[i] = 1 << i;
      vis[i] = false;
    }
    for (int i = 1; i != M; ++i) dp[i] = false;
    dp[0] = true;
    int n, cnt = 0, ans = 0;
    scanf("%d%s%s", &n, s, t);
    for (int i = 0; i != n; ++i) {
      mp[s[i] - 'a'] |= 1 << (t[i] - 'a');
    }
    for (int i = 0; i != SIG; ++i) {
      if (!vis[i]) {
        ++cnt;
        dfs(i);
      }
    }
    for (int i = 1; i != M; ++i) {
      int c = 0;
      for (int j = 0; j != SIG; ++j) {
        if (i >> j & 1) {
          if (!dp[i] && dp[i ^ 1 << j] && (i & mp[j]) == (1 << j)) {
            dp[i] = true;
          }
          ++c;
        }
      }
      if (dp[i] && c > ans) {
        ans = c;
      }
    }
    printf("%d\n", (SIG << 1) - cnt - ans);
  }
  return 0;
}
