#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f = ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
template <class T>
void ckmax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class T>
void ckmin(T &x, const T &y) {
  if (x > y) x = y;
}
long long absl(long long x) { return x < 0 ? -x : x; }
const int N = 100005;
int n, ans, res;
int a[N], b[N];
int g[20], all;
int f[20];
int fa[20];
int getf(int x) { return fa[x] == x ? x : fa[x] = getf(fa[x]); }
int tp[20];
void dfs(int k, int s) {
  if (k == 20) {
    res = min(res, ans - s);
    return;
  }
  dfs(k + 1, s);
  if (~all >> k & 1) return;
  vector<int> bkf(f, f + 20), btp(tp, tp + 20);
  int flag = 1;
  int flag2 = 0;
  for (int i = (0); i <= (19); i++)
    if (g[i] >> k & 1) {
      tp[i] = 1;
      if (bkf[k] >> i & 1) {
        flag = 0;
        break;
      }
      f[i] |= f[k];
      for (int j = (0); j <= (19); j++)
        if (f[j] >> i & 1) f[j] |= f[k];
    }
  for (int i = (0); i <= (19); i++)
    if (getf(i) == getf(k)) flag2 |= !tp[i];
  if (flag && flag2) dfs(k + 1, s + 1);
  for (int i = (0); i <= (19); i++) f[i] = bkf[i], tp[i] = btp[i];
}
void solve() {
  n = read();
  {
    string s;
    cin >> s;
    assert((int)s.size() == n);
    for (int i = (0); i <= (n - 1); i++) a[i + 1] = s[i] - 'a';
    cin >> s;
    assert((int)s.size() == n);
    for (int i = (0); i <= (n - 1); i++) b[i + 1] = s[i] - 'a';
  }
  memset(g, 0, sizeof(g));
  for (int i = (1); i <= (n); i++) g[a[i]] |= 1 << b[i];
  for (int i = (0); i <= (19); i++)
    if (g[i] >> i & 1) g[i] ^= 1 << i;
  ans = 20;
  all = 0;
  for (int i = (0); i <= (19); i++) all |= g[i];
  {
    iota(fa, fa + 20, 0);
    for (int i = (0); i <= (19); i++)
      for (int j = (0); j <= (19); j++)
        if ((g[i] | 1 << i) & (g[j] | 1 << j)) fa[getf(i)] = getf(j);
    for (int i = (0); i <= (19); i++)
      if (getf(i) == i) ans--;
  }
  ans += __builtin_popcount(all);
  memset(f, 0, sizeof(f));
  memset(tp, 0, sizeof(tp));
  for (int i = (0); i <= (19); i++) f[i] |= 1 << i;
  res = 233;
  dfs(0, 0);
  cout << res << endl;
}
int main() {
  int T = read();
  while (T--) solve();
  return 0;
}
