#include <bits/stdc++.h>
int dag(std::vector<std::vector<int> > g, std::vector<int> wierz) {
  std::sort(wierz.begin(), wierz.end());
  auto kto = [&](int v) {
    assert(std::find(wierz.begin(), wierz.end(), v) != wierz.end());
    return std::lower_bound(wierz.begin(), wierz.end(), v) - wierz.begin();
  };
  int n = ((int)(wierz).size());
  std::vector<int> dp(1 << n);
  std::vector<int> hehe(n);
  for (int i = 0; i < (n); ++i)
    for (auto& j : (g[wierz[i]])) hehe[i] |= (1 << kto(j));
  int best = 0;
  dp[0] = 1;
  for (int mask = (1); mask < (1 << n); ++mask) {
    for (int i = 0; i < (n); ++i)
      if (mask & (1 << i)) {
        dp[mask] |= dp[mask ^ (1 << i)] & ((hehe[i] & mask) == 0);
      }
    if (dp[mask]) best = std::max(best, __builtin_popcount(mask));
  }
  return best;
}
void solve(std::vector<std::vector<int> > g,
           std::vector<std::vector<int> > gg) {
  std::vector<bool> vis(20);
  std::vector<int> cur;
  std::function<void(int)> dfs = [&](int v) {
    vis[v] = true;
    cur.push_back(v);
    for (auto& ch : (gg[v]))
      if (!vis[ch]) dfs(ch);
  };
  int ans = 0;
  for (int i = 0; i < (20); ++i)
    if (!vis[i]) {
      cur.clear();
      dfs(i);
      ans += 2 * ((int)(cur).size()) - 1 - dag(g, cur);
    }
  std::cout << ans << "\n";
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  int t;
  std::cin >> t;
  while (t--) {
    int n;
    std::cin >> n;
    std::string a, b;
    std::cin >> a >> b;
    std::vector<std::vector<int> > g(20);
    std::vector<std::vector<int> > gg(20);
    for (int i = 0; i < (n); ++i) {
      if (a[i] != b[i]) {
        g[a[i] - 'a'].push_back(b[i] - 'a');
        gg[a[i] - 'a'].push_back(b[i] - 'a');
        gg[b[i] - 'a'].push_back(a[i] - 'a');
      }
    }
    solve(g, gg);
  }
  return 0;
}
