#include <bits/stdc++.h>
const int kN = 100000 + 5;
char A[kN], B[kN];
int n;
int solve() {
  std::vector<int> graph(20);
  for (int i = 0; i < n; ++i) {
    if (A[i] != B[i]) {
      graph[A[i] - 'a'] |= 1 << (B[i] - 'a');
    }
  }
  std::vector<int> isdag(1 << 20);
  isdag[0] = true;
  for (int mask = 1; mask < 1 << 20; ++mask) {
    for (int u = 0; u < 20; ++u)
      if (mask >> u & 1) {
        isdag[mask] |= isdag[mask ^ 1 << u] && (mask & graph[u]) == 0;
      }
  }
  int ret = 0;
  int vis = 0;
  for (int i = 0; i < 20; ++i)
    if (~vis >> i & 1) {
      int w = 0;
      std::queue<int> que;
      que.emplace(i);
      vis |= 1 << i;
      while (!que.empty()) {
        int u = que.front();
        que.pop();
        w |= 1 << u;
        for (int v = 0; v < 20; ++v)
          if ((graph[u] >> v & 1) || (graph[v] >> u & 1)) {
            if (~vis >> v & 1) {
              que.emplace(v);
              vis |= 1 << v;
            }
          }
      }
      int cnt = __builtin_popcount(w);
      int m = 0;
      for (int mask = w;; mask = (mask - 1) & w) {
        if (isdag[mask]) m = std::max(m, __builtin_popcount(mask));
        if (mask == 0) break;
      }
      ret += 2 * cnt - m - 1;
    }
  return ret;
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    scanf("%d%s%s", &n, A, B);
    printf("%d\n", solve());
  }
}
