#include <bits/stdc++.h>
using namespace std;
int f[30], to[30];
int findx(int x) { return f[x] == x ? x : f[x] = findx(f[x]); }
void unite(int x, int y) {
  x = findx(x);
  y = findx(y);
  if (x == y) return;
  f[x] = y;
}
bool dp[1 << 21];
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    map<int, set<int>> graph;
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    memset(to, 0, sizeof(to));
    for (int i = 0; i < 20; i++) f[i] = i;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        int u = a[i] - 'a';
        int v = b[i] - 'a';
        to[u] |= (1 << v);
        unite(u, v);
      }
    }
    memset(dp, 0, sizeof(dp));
    int ans = 40;
    for (int i = 0; i < 20; i++)
      if (findx(i) == i) ans--;
    dp[0] = true;
    int maxs = 0;
    for (int s = 0; s < (1 << 20); s++) {
      if (!dp[s]) continue;
      int cur = 0;
      for (int i = 0; i < 20; i++) {
        int tmp = 1 << i;
        if (tmp & s) cur++;
        if (to[i] & s) continue;
        dp[s | tmp] = true;
      }
      maxs = max(maxs, cur);
    }
    cout << ans - maxs << endl;
  }
  return 0;
}
