#include <bits/stdc++.h>
using namespace std;
const int MX = 20;
bool been[MX];
vector<int> adj[MX];
int on[MX];
int mask_all = 0;
void dfs(int node) {
  if (been[node]) return;
  been[node] = 1;
  mask_all = mask_all + (1 << node);
  for (auto k : adj[node]) dfs(k);
}
int sub = 0;
bool dag[1 << MX];
int bits[1 << MX];
void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < MX; i++) {
    adj[i] = {};
    on[i] = 0;
  }
  for (int i = 0; i < n; i++)
    if (a[i] != b[i]) {
      adj[a[i] - 'a'].push_back(b[i] - 'a');
      adj[b[i] - 'a'].push_back(a[i] - 'a');
      on[a[i] - 'a'] = on[a[i] - 'a'] | (1 << (b[i] - 'a'));
    }
  memset(dag, 0, sizeof(dag));
  dag[0] = 1;
  for (int i = 1; i < (1 << MX); i++) {
    for (int lst = 0; lst < MX && dag[i] == 0; lst++) {
      if ((i & (1 << lst))) {
        if (dag[i - (1 << lst)] && (on[lst] & i) == 0) dag[i] = 1;
      }
    }
  }
  int ret = 2 * MX;
  for (int i = 0; i < MX; i++) been[i] = 0;
  for (int i = 0; i < MX; i++)
    if (been[i] == 0) {
      mask_all = 0;
      dfs(i);
      sub = 0;
      for (int j = mask_all; j; j = (j - 1) & mask_all)
        if (dag[j]) sub = max(sub, bits[j]);
      ret = ret - 1 - sub;
    }
  cout << ret << endl;
}
int main() {
  for (int i = 0; i < (1 << MX); i++) bits[i] = bits[i / 2] + i % 2;
  int t;
  cin >> t;
  while (t) {
    t--;
    solve();
  }
  return 0;
}
