#include <bits/stdc++.h>
using namespace std;
void dfs(int v, const vector<vector<bool>>& e, vector<bool>& used,
         vector<int>& comp) {
  comp.push_back(v);
  used[v] = true;
  for (int u = 0; u < 20; ++u) {
    if (!used[u] && (e[u][v] || e[v][u])) {
      dfs(u, e, used, comp);
    }
  }
}
int MaxDAG(const vector<int>& e_mask) {
  int n = e_mask.size();
  vector<bool> is_dag(1 << n);
  is_dag[0] = true;
  int max_size = 0;
  for (int mask = 1; mask < (1 << n); ++mask) {
    int size = 0;
    for (int u = 0; u < n; ++u) {
      if (mask & (1 << u)) {
        size += 1;
        is_dag[mask] = is_dag[mask] ||
                       (is_dag[mask ^ (1 << u)] && ((mask & e_mask[u]) == 0));
      }
    }
    if (is_dag[mask]) {
      max_size = max(max_size, size);
    }
  }
  return max_size;
}
int MaxDAG(const vector<vector<bool>>& e, const vector<int>& vs) {
  vector<int> new_e;
  for (auto v : vs) {
    new_e.push_back(0);
    for (int i = vs.size() - 1; i >= 0; --i) {
      int u = vs[i];
      new_e.back() *= 2;
      new_e.back() += e[v][u];
    }
  }
  return MaxDAG(new_e);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string A, B;
    cin >> A >> B;
    vector<vector<bool>> e(20, vector<bool>(20, 0));
    for (int i = 0; i < n; ++i) {
      if (A[i] != B[i]) {
        e[A[i] - 'a'][B[i] - 'a'] = true;
      }
    }
    vector<bool> used(20);
    int ans = 0;
    for (int i = 0; i < 20; ++i) {
      if (!used[i]) {
        vector<int> vs;
        dfs(i, e, used, vs);
        ans += 2 * vs.size() - 1 - MaxDAG(e, vs);
      }
    }
    cout << ans << "\n";
  }
}
