#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void program();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  program();
}
const int MX = 20, BIT = (1 << MX);
int testCases;
int n;
string a, b;
vector<int> adj[MX];
int dp[BIT];
bitset<MX> visited;
int comp;
int reach[MX];
void dfs(int u) {
  if (visited[u]) return;
  visited[u] = 1;
  for (int v : adj[u]) dfs(v);
}
void program() {
  cin >> testCases;
  while (testCases--) {
    cin >> n >> a >> b;
    for (int i = int(0); i < int(n); i++) a[i] -= 'a';
    for (int i = int(0); i < int(n); i++) b[i] -= 'a';
    for (int i = int(0); i < int(MX); i++) reach[i] = 0;
    for (int i = int(0); i < int(MX); i++) adj[i].clear();
    for (int i = int(0); i < int(n); i++)
      if (a[i] != b[i]) {
        reach[a[i]] |= (1 << b[i]);
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
      };
    comp = 0;
    visited.reset();
    for (int i = int(0); i < int(MX); i++)
      if (!visited[i]) dfs(i), comp++;
    int mx = 0;
    for (int i = int(0); i < int(BIT); i++) {
      dp[i] = (i == 0 ? 1 : 0);
      for (int j = int(0); j < int(MX); j++)
        if (i & (1 << j)) {
          dp[i] |= (dp[i ^ (1 << j)] && ((i & reach[j]) == 0));
        }
      if (dp[i]) mx = max(mx, __builtin_popcount(i));
    }
    int ans = 2 * MX - comp - mx;
    cout << ans << endl;
  }
}
