#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    const int m = 20;
    int cmp[m], adj[m];
    memset(cmp, 0, sizeof(cmp));
    for (int i = 0; i < m; i++) cmp[i] = (1 << i);
    memset(adj, 0, sizeof(adj));
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) adj[s[i] - 'a'] |= (1 << (t[i] - 'a'));
      for (int j = 0; j < m; j++)
        if (cmp[j] & ((1 << (s[i] - 'a')) | (1 << (t[i] - 'a'))))
          cmp[j] = (cmp[j] | cmp[s[i] - 'a'] | cmp[t[i] - 'a']);
    }
    int ans = 0;
    bool mark[m];
    memset(mark, 0, sizeof(mark));
    for (int v = 0; v < m; v++) {
      if (mark[v]) continue;
      vector<int> cur;
      for (int i = 0; i < m; i++) {
        if ((1 << i) & cmp[v]) {
          mark[i] = true;
          cur.push_back(i);
        }
      }
      int hlpM = cur.size();
      bool is_dag[1 << hlpM];
      memset(is_dag, 0, sizeof(is_dag));
      is_dag[0] = true;
      int maxDAG = 0;
      for (int i = 1; i < (1 << hlpM); i++) {
        int msk = 0;
        for (int j = 0; j < hlpM; j++)
          if ((1 << j) & i) msk |= (1 << cur[j]);
        for (int j = 0; j < hlpM; j++)
          if ((1 << j) & i)
            is_dag[i] |= (is_dag[i ^ (1 << j)] & ((adj[cur[j]] & msk) == 0));
        if (is_dag[i]) maxDAG = max(maxDAG, __builtin_popcount(i));
      }
      ans += 2 * cur.size() - maxDAG - 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
