#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int reach[N];
int dsu[N];
int get(int v) {
  if (dsu[v] == v) {
    return v;
  }
  return dsu[v] = get(dsu[v]);
}
void merge(int a, int b) {
  a = get(a);
  b = get(b);
  if (a == b) {
    return;
  }
  dsu[b] = a;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    iota(dsu, dsu + N, 0);
    fill(reach, reach + N, 0);
    for (int i = 0; i < n; ++i) {
      if (a[i] != b[i]) {
        merge(a[i] - 'a', b[i] - 'a');
        reach[a[i] - 'a'] |= 1 << (b[i] - 'a');
      }
    }
    int cnt = 0;
    for (int i = 0; i < 20; ++i) {
      cnt += dsu[i] == i;
    }
    int dag = 0;
    vector<int> dp(1 << N);
    dp[0] = true;
    for (int mask = 1; mask < (1 << N); ++mask) {
      for (int i = 0; i < N; ++i) {
        if (!(mask & (1 << i))) {
          continue;
        }
        if (!(reach[i] & mask)) {
          dp[mask] |= dp[mask ^ (1 << i)];
        }
      }
      if (dp[mask]) {
        dag = max(dag, __builtin_popcount(mask));
      }
    }
    cout << 2 * N - cnt - dag << "\n";
  }
}
