#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char a[maxn], b[maxn];
vector<int> g[26];
int reach[26];
int vis[26];
int cnt;
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  for (int v : g[u]) dfs(v);
}
int dp[1 << 20];
int bin[1 << 20];
int ap[26];
int main() {
  for (int i = (1); i < (1 << 20); ++i) bin[i] = bin[i - ((i) & (-(i)))] + 1;
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    scanf("%s%s", a, b);
    for (int i = (0); i < (26); ++i) g[i].clear();
    memset(reach, 0, sizeof reach);
    memset(ap, 0, sizeof ap);
    for (int i = (0); i < (n); ++i) {
      if (a[i] != b[i])
        reach[a[i] - 'a'] |= (1 << (b[i] - 'a')),
            g[a[i] - 'a'].push_back(b[i] - 'a'),
            g[b[i] - 'a'].push_back(a[i] - 'a'),
            ap[a[i] - 'a'] = ap[b[i] - 'a'] = 1;
    }
    int mis = 0;
    for (int i = (0); i < (20); ++i)
      if (!ap[i]) mis |= (1 << i);
    cnt = 0;
    memset(vis, 0, sizeof vis);
    for (int i = (0); i < (26); ++i)
      if (!vis[i] && ap[i]) cnt++, dfs(i);
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    int mx = 0;
    for (int mask = (1); mask < ((1 << 20)); ++mask) {
      if (mask & mis) continue;
      for (int i = (0); i < (20); ++i) {
        if ((mask >> i & 1) && (mask & reach[i]) == 0)
          dp[mask] |= dp[mask ^ (1 << i)];
      }
      if (dp[mask]) mx = max(mx, bin[mask]);
    }
    int num = 20 - bin[mis];
    int ans = 2 * num - cnt - mx;
    cout << ans << endl;
  }
  return 0;
}
