#include <bits/stdc++.h>
using namespace std;
const int ALP = 20;
bool mrk[ALP], f[(1 << ALP)], g[ALP][ALP];
string A, B;
int n, who[ALP], glob;
void dfs(int v) {
  mrk[v] = 1;
  for (int u = 0; u < ALP; u++)
    if (!mrk[u] && (g[v][u] || g[u][v])) dfs(u);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int qq;
  cin >> qq;
  for (; qq; qq--) {
    cin >> n >> A >> B;
    for (int i = 0; i < ALP; i++)
      for (int j = 0; j < ALP; j++) g[i][j] = 0;
    for (int i = 0; i < n; i++) {
      int c1 = (A[i] - 'a');
      int c2 = (B[i] - 'a');
      if (c1 != c2) g[c1][c2] = 1;
    }
    int cnt = 0;
    fill(mrk, mrk + ALP, 0);
    for (int i = 0; i < ALP; i++)
      if (!mrk[i]) {
        dfs(i);
        cnt++;
      }
    for (int i = 0; i < ALP; i++) {
      fill(mrk, mrk + ALP, 0);
      who[i] = 0;
      glob = i;
      for (int u = 0; u < ALP; u++)
        if (g[i][u]) who[i] |= (1 << u);
    }
    f[0] = 1;
    int mx = 0;
    for (int msk = 1; msk < (1 << ALP); msk++) {
      f[msk] = 0;
      for (int v = 0; v < ALP; v++)
        if ((msk & (1 << v)) && f[msk ^ (1 << v)] && !(msk & who[v])) {
          f[msk] = 1;
          break;
        }
      if (f[msk]) mx = max(mx, __builtin_popcount(msk));
    }
    cout << ALP * 2 - mx - cnt << '\n';
  }
  return 0;
}
