#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
const int sigma = 20;
vector<pair<int, int>> tosort;
void precalc() {
  tosort.clear();
  for (int i = 0; i < (1 << sigma); ++i) {
    tosort.push_back(make_pair(__builtin_popcount(i), i));
  }
  sort(tosort.begin(), tosort.end());
}
const int maxn = (int)1e5 + 5;
char tmp[maxn];
int n;
string s, t;
bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  scanf("%s", tmp);
  s = tmp;
  scanf("%s", tmp);
  t = tmp;
  return true;
}
int g[sigma];
int msk, used, inside;
void getComp(int v) {
  used |= (1 << v);
  for (int u = 0; u < sigma; ++u) {
    if (!(used & (1 << u)) && ((g[v] & (1 << u)) || (g[u] & (1 << v)))) {
      getComp(u);
    }
  }
}
bool getCycle(int v) {
  used |= (1 << v);
  inside |= (1 << v);
  int gg = (g[v] & ~msk & ~(1 << v));
  if (gg & inside) {
    return true;
  }
  while (gg & ~used) {
    int u = __builtin_ctz(gg & ~used);
    if (getCycle(u)) {
      return true;
    }
  }
  inside &= ~(1 << v);
  return false;
}
void solve() {
  for (int i = 0; i < sigma; ++i) {
    g[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    g[s[i] - 'a'] |= (1 << (t[i] - 'a'));
  }
  int res = sigma;
  {
    used = 0;
    for (int i = 0; i < sigma; ++i) {
      if (!(used & (1 << i))) {
        res--;
        getComp(i);
      }
    }
  }
  for (int it = 0; it < ((int)(tosort).size()); ++it) {
    msk = tosort[it].second;
    used = 0;
    inside = 0;
    bool c = false;
    for (int i = 0; i < sigma; ++i) {
      if (!(used & (1 << i)) && getCycle(i)) {
        c = true;
        break;
      }
    }
    if (!c) {
      res += tosort[it].first;
      break;
    }
  }
  printf("%d\n", res);
}
int main() {
  precalc();
  int t;
  scanf("%d", &t);
  while (read()) {
    solve();
  }
  return 0;
}
