#include <bits/stdc++.h>
using namespace std;
struct DSU {
  vector<int> root, sz;
  DSU(int n) {
    sz = root = vector<int>(n + 1);
    for (int i = 0; i <= n; ++i) {
      root[i] = i;
      sz[i] = 1;
    }
  }
  int find(int a) {
    if (root[a] != a) {
      root[a] = find(root[a]);
    }
    return root[a];
  }
  bool join(int a, int b) {
    if (same(a, b)) return 0;
    int x = find(a), y = find(b);
    if (sz[x] > sz[y]) swap(x, y);
    sz[y] += sz[x];
    root[x] = y;
    return 1;
  }
  bool same(int a, int b) { return find(a) == find(b); }
};
void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  int c = 0;
  DSU d(20);
  vector<int> g(1 << 20), dp(1 << 20, 0);
  for (int i = 0; i < n; ++i) {
    a[i] -= 'a';
    b[i] -= 'a';
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[i]) {
      c += d.join(a[i], b[i]);
      g[a[i]] |= (1 << b[i]);
    }
  }
  int mx = 0;
  dp[0] = 1;
  for (int mask = 0; mask < (1 << 20); ++mask) {
    if (dp[mask] == 0) continue;
    mx = max(__builtin_popcount(mask), mx);
    for (int i = 0; i < 20; ++i) {
      g[i] |= (1 << i);
      if ((mask & g[i]) == 0) {
        dp[mask | (1 << i)] = 1;
      }
    }
  }
  cout << c + 20 - mx << '\n';
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
