#include <bits/stdc++.h>
const int SIGMA = 20;
int outEdges[SIGMA];
bool isDAG[1 << SIGMA];
bool isEdge[SIGMA][SIGMA];
bool visited[SIGMA];
void dfs(int u) {
  visited[u] = true;
  for (int v = 0; v < SIGMA; v++) {
    if (isEdge[u][v]) {
      if (!visited[v]) {
        dfs(v);
      }
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  for (int _ = 0; _ < t; _++) {
    int n;
    scanf("%d", &n);
    char A[n + 1];
    char B[n + 1];
    scanf("%s%s", A, B);
    for (int i = 0; i < SIGMA; i++) {
      for (int j = 0; j < SIGMA; j++) {
        isEdge[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      isEdge[A[i] - 'a'][B[i] - 'a'] = true;
      isEdge[B[i] - 'a'][A[i] - 'a'] = true;
    }
    for (int i = 0; i < SIGMA; i++) {
      visited[i] = false;
    }
    int components = 0;
    for (int u = 0; u < SIGMA; u++) {
      if (!visited[u]) {
        components++;
        dfs(u);
      }
    }
    for (int i = 0; i < SIGMA; i++) {
      outEdges[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      outEdges[A[i] - 'a'] |= 1 << (B[i] - 'a');
    }
    int maxDAG = 0;
    isDAG[0] = true;
    for (int mask = 1; mask < (1 << SIGMA); mask++) {
      isDAG[mask] = false;
      for (int i = 0, bit = 1; i < SIGMA; i++, bit <<= 1) {
        if ((mask & bit) == bit) {
          isDAG[mask] |=
              isDAG[mask ^ bit] && ((outEdges[i] & (mask ^ bit)) == 0);
        }
      }
      if (isDAG[mask]) {
        maxDAG = std::max(maxDAG, __builtin_popcount(mask));
      }
    }
    int answer = (maxDAG - components) + 2 * (SIGMA - maxDAG);
    printf("%d\n", answer);
  }
  return 0;
}
