#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > graph;
vector<int> AL;
vector<int> visited;
void dfs(int u) {
  visited[u] = 1;
  for (auto v : graph[u]) {
    if (!visited[v]) {
      dfs(v);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    AL.assign(20, 0);
    graph.assign(20, vector<int>());
    visited.assign(20, 0);
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        AL[a[i] - 'a'] |= 1 << (b[i] - 'a');
        graph[a[i] - 'a'].push_back(b[i] - 'a');
        graph[b[i] - 'a'].push_back(a[i] - 'a');
      }
    }
    int numCC = 0;
    for (int i = 0; i < 20; i++) {
      if (!visited[i]) {
        dfs(i);
        numCC++;
      }
    }
    int ans = 0;
    vector<bool> c(1 << 20);
    c[0] = true;
    for (int mask = 0; mask < (1 << 20); mask++) {
      if (c[mask]) {
        ans = max(ans, __builtin_popcount(mask));
        for (int i = 0; i < 20; i++) {
          if (((~mask >> i) & 1) && (AL[i] & mask) == 0) {
            c[mask | (1 << i)] = true;
          }
        }
      }
    }
    cout << 2 * 20 - ans - numCC << endl;
  }
  return 0;
}
