#include <bits/stdc++.h>
using namespace std;
const int Alp = 20;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int test;
  cin >> test;
  while (test--) {
    int len;
    string a, b;
    cin >> len >> a >> b;
    vector<int> adj(Alp);
    vector<vector<int>> G(Alp);
    for (int i = 0; i < len; ++i)
      if (a[i] != b[i]) {
        adj[a[i] - 'a'] |= 1 << (b[i] - 'a');
        G[a[i] - 'a'].push_back(b[i] - 'a');
        G[b[i] - 'a'].push_back(a[i] - 'a');
      }
    vector<bool> mark(Alp);
    function<void(int)> dfs = [&](int u) {
      mark[u] = true;
      for (auto v : G[u])
        if (!mark[v]) dfs(v);
    };
    int comp = 0;
    for (int i = 0; i < Alp; ++i)
      if (!mark[i]) dfs(i), ++comp;
    int ans = 0;
    vector<bool> dp(1 << Alp);
    dp[0] = true;
    for (int mask = 0; mask < 1 << Alp; ++mask)
      if (dp[mask]) {
        ans = max(ans, __builtin_popcount(mask));
        for (int u = 0; u < Alp; ++u)
          if ((adj[u] & mask) == 0) dp[mask | 1 << u] = true;
      }
    cout << 2 * Alp - comp - ans << "\n";
  }
  return 0;
}
