#include <bits/stdc++.h>
using namespace std;
const int N = 20, M = 1e5 + 10;
int fa[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int n, to[N];
char a[M], b[M];
bool dp[1 << N];
void solve() {
  scanf("%d", &n);
  scanf("%s", a);
  scanf("%s", b);
  memset(to, 0, sizeof(to));
  int cc = 20;
  for (int i = (0); i < (20); ++i) fa[i] = i;
  for (int i = (0); i < (n); ++i) {
    int x = a[i] - 'a', y = b[i] - 'a';
    if (x != y) {
      to[x] |= 1 << y;
      cc -= find(x) != find(y);
      fa[find(x)] = find(y);
    }
  }
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  int ans = 0;
  for (int i = (0); i < (1 << 20); ++i)
    if (dp[i]) {
      int cnt = 0;
      for (int j = (0); j < (20); ++j) {
        if (i >> j & 1) {
          cnt++;
        } else if ((to[j] & i) == 0) {
          dp[i | (1 << j)] = 1;
        }
      }
      ans = max(ans, cnt);
    }
  ans = 20 + (20 - ans) - cc;
  printf("%d\n", ans);
}
signed main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
