#include <bits/stdc++.h>
using namespace std;
vector<set<int>> out(20), in(20);
vector<int> tmp, id(20), out2(20), in2(20);
bool vis[20];
const int MAXN = 1 << 20;
vector<int> dp(MAXN);
bool vis2[MAXN];
int ans = 0;
void dfs(int u) {
  vis[u] = 1;
  id[u] = (int)(tmp.size());
  tmp.push_back(u);
  for (int v : in[u])
    if (!vis[v]) dfs(v);
  for (int v : out[u])
    if (!vis[v]) dfs(v);
}
void solve() {
  int N = (int)(tmp.size());
  queue<int> bfs;
  bfs.push(0);
  vis2[0] = 1;
  while (!bfs.empty()) {
    int first = bfs.front();
    bfs.pop();
    for (int i = 0; i < N; i++) {
      if ((1 << i) & first) continue;
      if ((in2[i] & first) == in2[i])
        dp[(1 << i) | first] = min(dp[(1 << i) | first], dp[first] + 1);
      else
        dp[(1 << i) | first] = min(dp[(1 << i) | first], dp[first] + 2);
      if (!vis2[(1 << i) | first])
        bfs.push((1 << i) | first), vis2[(1 << i) | first] = 1;
    }
  }
  ans += dp[(1 << N) - 1] - 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    ans = 0;
    int n;
    cin >> n;
    for (int i = 0; i < 20; i++)
      out[i].clear(), in[i].clear(), vis[i] = 0, id[i] = 0;
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (a[i] == b[i]) continue;
      out[a[i] - 'a'].insert(b[i] - 'a');
      in[b[i] - 'a'].insert(a[i] - 'a');
    }
    for (int i = 0; i < 20; i++) {
      if (vis[i]) continue;
      if ((int)(out[i].size()) + (int)(in[i].size()) == 0) continue;
      tmp.clear();
      dfs(i);
      for (int j = 0; j < 20; j++) in2[j] = out2[j] = 0;
      for (int u : tmp) {
        for (int v : in[u]) in2[id[u]] |= (1 << id[v]);
        for (int v : out[u]) out2[id[u]] |= (1 << id[v]);
      }
      for (int j = 0; j < (1 << (int)(tmp.size())); j++)
        dp[j] = 1e9, vis2[j] = 0;
      dp[0] = 0;
      solve();
    }
    cout << ans << '\n';
  }
  return 0;
}
