#include <bits/stdc++.h>
using namespace std;
bool x[20][20];
bool z[20];
vector<int> Bfs(int a) {
  z[a] = true;
  vector<int> q{a};
  for (int j = 0; j < q.size(); ++j) {
    int s = q[j];
    for (int i = 0; i < 20; ++i) {
      if (z[i]) continue;
      if (x[i][s] || x[s][i]) {
        q.push_back(i);
        z[i] = true;
        continue;
      }
    }
  }
  return q;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int times;
  cin >> times;
  while (times--) {
    int n;
    cin >> n;
    string p, q;
    cin >> p >> q;
    memset(x, 0, sizeof(x));
    memset(z, 0, sizeof(z));
    for (int i = 0; i < n; ++i) {
      if (p[i] == q[i]) continue;
      x[p[i] - 'a'][q[i] - 'a'] = true;
    }
    int ans = 0;
    for (int i = 0; i < 20; ++i) {
      if (z[i]) continue;
      vector<int> y = Bfs(i);
      if (y.size() == 1) continue;
      int m = y.size();
      vector<int> reach(m);
      for (int j = 0; j < m; ++j) {
        for (int k = 0; k < m; ++k) {
          if (x[y[j]][y[k]]) reach[j] ^= (1 << k);
        }
      }
      int cnt = 0;
      vector<bool> f(1 << m);
      f[0] = true;
      for (int j = 0; j < (1 << m); ++j) {
        if (!f[j]) continue;
        cnt = max(cnt, __builtin_popcount(j));
        for (int k = 0; k < m; ++k) {
          if (j & (1 << k)) continue;
          if (reach[k] & j) continue;
          f[j ^ (1 << k)] = true;
        }
      }
      ans += m + m - 1 - cnt;
    }
    cout << ans << endl;
  }
  return 0;
}
