#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n, t, dor, ans, mark[N], low_bit[(1 << N)], m[N][N], dp[(1 << N)];
int F[N][(1 << N)];
string a, b;
vector<int> g[N];
void make() {
  for (int mask = 1; mask < (1 << N); mask++)
    for (int i = 0; i < N; i++)
      if ((mask % (1 << (i + 1)) >= (1 << i))) {
        low_bit[mask] = i;
        return;
      }
}
void clear() {
  ans = N;
  fill(mark, mark + N, 0);
  for (int i = 0; i < N; i++) g[i].clear();
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) m[i][j] = 0;
  for (int i = 0; i < n; i++)
    if (a[i] != b[i]) {
      g[a[i] - 'a'].push_back(b[i] - 'a'), g[b[i] - 'a'].push_back(a[i] - 'a');
      m[a[i] - 'a'][b[i] - 'a'] = 1;
    }
}
void dfs(int x) {
  mark[x] = 1;
  for (int i = 0; i < g[x].size(); i++)
    if (!mark[g[x][i]]) dfs(g[x][i]);
}
void solve(int x, int mask) {
  if ((mask % (1 << (x + 1)) >= (1 << x))) return;
  for (int i = 0; i < N; i++)
    if ((mask % (1 << (i + 1)) >= (1 << i))) {
      F[x][mask] = (F[x][mask - (1 << i)] || m[x][i]);
      return;
    }
}
void calc(int mask) {
  dp[mask] = N * N;
  for (int i = 0; i < N; i++)
    if ((mask % (1 << (i + 1)) >= (1 << i)))
      dp[mask] = min(dp[mask], dp[mask - (1 << i)] + F[i][mask - (1 << i)]);
  ;
}
void do_it() {
  for (int i = 0; i < N; i++)
    for (int mask = 1; mask < (1 << N); mask++) solve(i, mask);
  for (int i = 1; i < (1 << N); i++) calc(i);
}
void solve() {
  clear();
  for (int i = 0; i < N; i++)
    if (!mark[i]) dfs(i), ans--;
  do_it();
  cout << ans + dp[(1 << N) - 1] << '\n';
}
int main() {
  make();
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> a >> b;
    solve();
  }
}
