#include <bits/stdc++.h>
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    int N;
    string A, B;
    cin >> N >> A >> B;
    vector<vector<bool>> adj(20, vector<bool>(20, false));
    vector<vector<bool>> adj2(20, vector<bool>(20, false));
    for (int i = 0; i < 20; i++) adj[i][i] = adj2[i][i] = true;
    for (int i = 0; i < N; i++) {
      adj[A[i] - 'a'][B[i] - 'a'] = true;
      adj2[A[i] - 'a'][B[i] - 'a'] = true;
      adj2[B[i] - 'a'][A[i] - 'a'] = true;
    }
    for (int k = 0; k < 20; k++) {
      for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 20; j++) {
          if (adj2[i][k] && adj2[k][j]) adj2[i][j] = true;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < 20; i++) {
      bool is_first = true;
      for (int j = 0; j < i; j++) {
        if (adj2[i][j]) {
          is_first = false;
        }
      }
      if (!is_first) continue;
      int M = 0;
      vector<int> alive;
      for (int j = i; j < 20; j++) {
        if (adj2[i][j]) alive.push_back(j);
      }
      M = int(alive.size());
      vector<int32_t> cur_adj(M);
      for (int j = 0; j < M; j++) {
        for (int k = 0; k < M; k++) {
          if (adj[alive[j]][alive[k]]) cur_adj[j] |= (1 << k);
        }
      }
      int best = 0;
      vector<bool> is_good(1 << M);
      is_good[0] = true;
      for (int m = 0; m < (1 << M); m++) {
        if (!is_good[m]) continue;
        best = max(best, __builtin_popcount(m));
        for (int j = 0; j < M; j++) {
          if (m & (1 << j)) continue;
          if (cur_adj[j] & m) continue;
          is_good[m | (1 << j)] = true;
        }
      }
      ans += 2 * M - 1 - best;
    }
    cout << ans << '\n';
  }
  return 0;
}
