#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }
signed main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    vi adj(20);
    vector<vi> G(20);
    for (int i = 0; i < a.size(); i++)
      if (a[i] != b[i]) {
        int x = a[i] - 'a', y = b[i] - 'a';
        adj[x] |= 1 << (y), G[x].push_back(y), G[y].push_back(x);
      }
    vi msk(20);
    int comp = 0;
    function<void(int)> dfs = [&](int x) {
      msk[x] = 1;
      for (int y : G[x])
        if (!msk[y]) dfs(y);
    };
    for (int i = 0; i < 20; i++)
      if (!msk[i]) dfs(i), comp++;
    cerr << "comp = " << comp << endl;
    vi f(1 << 20);
    f[0] = 1;
    int ans = 0;
    for (int i = 0; i < (1 << 20); i++)
      if (f[i]) {
        ans = max(ans, __builtin_popcount(i));
        for (int j = 0; j < 20; j++)
          if ((~i >> j & 1) && (adj[j] & i) == 0) f[i | (1 << j)] |= 1;
      }
    cerr << "ans = " << ans << endl;
    cout << 40 - comp - ans << endl;
  }
  fprintf(stderr, "time=%.4f\n", (db)clock() / CLOCKS_PER_SEC);
  return 0;
}
