#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using pii = pair<int, int>;
struct DSU {
  vector<int> s;
  int num;
  DSU(int n) : s(n, -1), num(n) {}
  int find(int i) { return s[i] < 0 ? i : s[i] = find(s[i]); }
  bool join(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return false;
    if (a < b) swap(a, b);
    s[a] += s[b], s[b] = a;
    num--;
    return true;
  }
  int size(int i) { return -s[find(i)]; }
  bool same(int a, int b) { return find(a) == find(b); }
};
const int B = 20;
int dp[1 << B];
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  vi adj(B), radj(B);
  DSU dsu(B);
  for (int i = 0; i < n; i++) {
    adj[t[i] - 'a'] |= 1 << (s[i] - 'a');
    radj[s[i] - 'a'] |= 1 << (t[i] - 'a');
    dsu.join(t[i] - 'a', s[i] - 'a');
  }
  int ans = 2 * B - dsu.num;
  memset(dp, 0, sizeof(dp));
  for (int mask = 0; mask < (1 << B); mask++)
    for (int k = 0; k < B; k++) {
      if (mask & (1 << k)) continue;
      dp[mask | (1 << k)] = max(dp[mask], dp[mask | (1 << k)]);
      if ((adj[k] & mask) == 0)
        dp[mask | (1 << k)] = max(1 + dp[mask], dp[mask | (1 << k)]);
    }
  ans -= dp[(1 << B) - 1];
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
