#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long maxn = 1e6 + 100;
const long long maxc = 20;
long long n, m, k, t;
vector<long long> V[maxc];
vector<long long> V1[maxc];
long long used[maxc];
long long st2[maxn];
long long ans = 0;
void dfs(long long v) {
  used[v] = 2;
  for (auto v1 : V1[v]) {
    if (!used[v1]) {
      dfs(v1);
    }
  }
}
void solve(long long v) {
  dfs(v);
  long long q, w, e;
  vector<long long> nw;
  for (q = 0; q < maxc; q++) {
    if (used[q] == 2) {
      nw.push_back(q);
    }
  }
  vector<long long> I(maxc);
  for (q = 0; q < nw.size(); q++) {
    I[nw[q]] = q;
  }
  vector<bool> dp(st2[nw.size()]);
  dp[0] = 1;
  long long mxsz = 0;
  for (q = 1; q < st2[nw.size()]; q++) {
    for (w = 0; w < nw.size(); w++) {
      if ((st2[w] & q) != 0) {
        if (dp[q - st2[w]] == 0) {
          continue;
        }
        bool fail = 0;
        for (auto v1 : V[nw[w]]) {
          if ((st2[I[v1]] & q) != 0) {
            fail = 1;
            break;
          }
        }
        if (fail) {
          continue;
        }
        dp[q] = 1;
        mxsz = max(mxsz, (long long)__builtin_popcount(q));
        break;
      }
    }
  }
  ans += 2 * nw.size() - mxsz - 1;
  for (q = 0; q < maxc; q++) {
    if (used[q] == 2) {
      used[q] = 1;
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long q, w, e, a, b, c;
  st2[0] = 1;
  for (q = 1; q < 63; q++) {
    st2[q] = st2[q - 1] * 2;
  }
  cin >> t;
  for (long long it = 0; it < t; it++) {
    string s1, s2;
    for (q = 0; q < maxc; q++) {
      V[q].clear();
      used[q] = 0;
      V1[q].clear();
    }
    set<pair<long long, long long> > S;
    cin >> n;
    cin >> s1 >> s2;
    for (q = 0; q < n; q++) {
      if (s1[q] != s2[q]) {
        if (S.find(make_pair(s1[q], s2[q])) == S.end()) {
          S.insert(make_pair(s1[q], s2[q]));
          long long v1 = s1[q] - 'a', v2 = s2[q] - 'a';
          V[v1].push_back(v2);
          V1[v2].push_back(v1);
          V1[v1].push_back(v2);
        }
      }
    }
    for (q = 0; q < maxc; q++) {
      if (!used[q]) {
        solve(q);
      }
    }
    cout << ans << '\n';
    ans = 0;
  }
  return 0;
}
