#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
using pii = pair<int, int>;
using cd = complex<ld>;
int dfs(int v, vector<int> &used, const vector<int> &g) {
  used[v] = 1;
  int sz = 1;
  for (int u = 0; u < 20; u++) {
    if ((g[v] >> u & 1) && !used[u]) {
      sz += dfs(u, used, g);
    }
  }
  return sz;
}
void solve() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  vector<int> g1(20), g2(20);
  for (int i = 0; i < n; i++) {
    int v = s[i] - 'a', u = t[i] - 'a';
    if (v != u) {
      g1[u] |= 1 << v;
      g1[v] |= 1 << u;
      g2[v] |= 1 << u;
    }
  }
  int comp = 0;
  vector<int> used(20);
  vector<int> dp(1 << 20);
  for (int i = 0; i < 20; i++) {
    if (!used[i]) {
      dfs(i, used, g1);
      comp++;
    }
    dp[1 << i] = 1;
  }
  int res = 0;
  for (int mask = 0; mask < 1 << 20; mask++) {
    for (int bit = 0; bit < 20; bit++) {
      if (mask >> bit & 1) {
        dp[mask] |= dp[mask ^ (1 << bit)] && ((g2[bit] & mask) == 0);
      }
    }
    if (dp[mask]) {
      res = max(res, __builtin_popcount(mask));
    }
  }
  cout << 2 * 20 - comp - res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test;
  cin >> test;
  while (test-- > 0) {
    solve();
  }
  return 0;
}
