#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, fa[N], E[N];
char a[N], b[N];
bool f[1 << 20];
int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> a >> b;
    for (int i = 0; i < 20; i++) fa[i] = i, E[i] = 0;
    for (int i = 0; i < n; i++) {
      int u = a[i] - 'a', v = b[i] - 'a';
      fa[getf(u)] = getf(v);
      E[u] |= 1 << v;
    }
    int cnt = 0, ans = 0;
    for (int i = 0; i < 20; i++) cnt += getf(i) == i;
    memset(f, 0, sizeof(f));
    f[0] = 1;
    for (int s = 1; s < (1 << 20); s++) {
      for (int i = 0; i < 20; i++)
        if ((s >> i & 1) && (E[i] & (s ^ (1 << i))) == 0 && f[s ^ (1 << i)]) {
          f[s] = 1;
          break;
        }
      if (f[s]) ans = max(ans, __builtin_popcount(s));
    }
    cout << 40 - cnt - ans << '\n';
  }
  return 0;
}
