#include <bits/stdc++.h>
using namespace std;
const int pw = 20;
string alf = "abcdefghijklmnopqrstuv";
int mx2 = (1 << pw);
int g[pw][pw];
int used[pw];
int cycle = 0;
vector<int> inm;
void dfs(int u) {
  cycle = cycle || (used[u] == 1);
  if (used[u]) return;
  used[u] = 1;
  for (auto i : inm) {
    if (g[u][i]) {
      dfs(i);
    }
  }
  used[u] = 2;
}
void dfscnt(int u) {
  if (used[u]) return;
  used[u] = 1;
  for (int i = 0; i < pw; i++) {
    if (g[u][i]) dfscnt(i);
  }
}
void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < pw; i++) {
    for (int j = 0; j < pw; j++) {
      g[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    g[a[i] - 'a'][b[i] - 'a'] = 1;
  }
  for (int i = 0; i < pw; i++) {
    g[i][i] = 0;
  }
  int mx = 0;
  for (int m = 1; m < mx2; m++) {
    int c = 0;
    inm.resize(0);
    for (int i = 0; i < pw; i++) {
      used[i] = 0;
      if (m & (1 << i)) {
        c++;
        inm.push_back(i);
      }
    }
    if (c <= mx) continue;
    cycle = 0;
    for (auto i : inm) {
      if (cycle == 0) {
        dfs(i);
      }
    }
    if (cycle == 0) {
      mx = max(mx, c);
    }
  }
  for (int i = 0; i < pw; i++) {
    for (int j = 0; j < pw; j++) {
      g[i][j] = g[i][j] || g[j][i];
    }
  }
  int cnt = 0;
  for (int i = 0; i < pw; i++) {
    used[i] = 0;
  }
  for (int i = 0; i < pw; i++) {
    if (used[i]) continue;
    dfscnt(i);
    cnt++;
  }
  cout << pw * 2 - mx - cnt << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
