#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 1e9 + 7;
double eps = 1e-12;
long long mpow(long long a, long long b) {
  if (a == 0) return 0;
  if (b == 0) return 1;
  long long t1 = mpow(a, b / 2);
  t1 *= t1;
  t1 %= MOD;
  if (b % 2) t1 *= a;
  t1 %= MOD;
  return t1;
}
long long mpow(long long a, long long b, long long p) {
  if (a == 0) return 0;
  if (b == 0) return 1;
  long long t1 = mpow(a, b / 2, p);
  t1 *= t1;
  t1 %= p;
  if (b % 2) t1 *= a;
  t1 %= p;
  return t1;
}
long long modinverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
long long range(long long l, long long r) { return l + mt() % (r - l + 1); }
long long rev(long long v) { return mpow(v, MOD - 2); }
long long gr[20][20];
long long vis[20];
void dfs1(long long v) {
  vis[v] = 1;
  for (long long j = 0; j < 20; j++)
    if (gr[v][j] && !vis[j]) dfs1(j);
}
void solve() {
  long long n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (long long i = 0; i < 20; i++)
    for (long long j = 0; j < 20; j++) gr[i][j] = 0;
  long long mask[20];
  for (long long i = 0; i < n; i++) {
    if (s[i] != t[i]) gr[s[i] - 'a'][t[i] - 'a'] = 1;
  }
  for (long long i = 0; i < 20; i++) {
    mask[i] = 0;
    for (long long j = 0; j < 20; j++) {
      if (gr[i][j]) mask[i] |= (1 << j);
    }
  }
  long long ans = 40;
  bool dp[1 << 20];
  for (long long i = 0; i < 1 << 20; i++) dp[i] = 0;
  dp[(1 << 20) - 1] = 1;
  for (long long i = (1 << 20) - 1; i >= 0; i--) {
    for (long long j = 0; j < 20; j++) {
      if (!(i & (1 << j))) {
        dp[i] |= (dp[i | (1 << j)] & ((mask[j] & i) == mask[j]));
      }
    }
    if (dp[i]) ans = min(ans, (long long)(20 + __builtin_popcount(i)));
  }
  for (long long i = 0; i < 20; i++)
    for (long long j = 0; j < 20; j++) gr[i][j] |= gr[j][i];
  for (long long j = 0; j < 20; j++) vis[j] = 0;
  for (long long i = 0; i < 20; i++) {
    if (!vis[i]) {
      dfs1(i);
      ans--;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
