#include <bits/stdc++.h>
using namespace std;
const long long maxn = 20;
vector<long long> a[maxn];
vector<long long> b[maxn];
long long ans[1 << maxn];
bool used[maxn];
long long parent[maxn];
long long tim;
long long tout[maxn];
long long glav(long long x) {
  long long y = x;
  while (true) {
    if (parent[y] == (-1)) {
      return y;
    }
    y = parent[y];
  }
}
void merg(long long x, long long y) {
  x = glav(x);
  y = glav(y);
  if (x != y) parent[x] = y;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    tim = 0;
    for (long long i = 0; i < maxn; ++i) {
      parent[i] = (-1);
      a[i].clear();
      used[i] = false;
    }
    long long n;
    string s1, s2;
    cin >> n;
    cin >> s1 >> s2;
    for (long long i = 0; i < n; ++i) {
      merg(s1[i] - 'a', s2[i] - 'a');
      if ((s1[i] - 'a') == (s2[i] - 'a')) continue;
      a[s1[i] - 'a'].push_back(s2[i] - 'a');
    }
    for (long long i = 0; i < maxn; ++i) {
      sort(a[i].begin(), a[i].end());
      a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end());
    }
    set<long long> d;
    for (long long i = 0; i < maxn; ++i) {
      d.insert(glav(i));
    }
    long long o = d.size();
    long long sz = (1 << maxn);
    ans[0] = 0;
    for (long long mask = 1; mask < sz; ++mask) {
      ans[mask] = 1e18;
      bool h1 = false;
      for (long long i = 0; i < maxn; ++i) {
        long long r = 0;
        if ((1 << i) & mask) {
          for (auto v : a[i]) {
            if (((1 << v) & mask)) {
              r = 1;
              break;
            }
          }
        } else {
          continue;
        }
        if (!r) h1 = true;
        ans[mask] = min(ans[mask], ans[mask - (1 << i)] + r + 1);
      }
    }
    cout << ans[sz - 1] - d.size() << endl;
  }
  return 0;
}
