#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const long long MOD = 998244353;
bool ug[30][30], col[30];
vector<int> g[N];
int vrj[N], qan[20][N], dp[N], pox[N];
vector<int> tv;
void dfs(int v) {
  col[v] = true;
  tv.push_back(v);
  for (auto to : g[v]) {
    if (!col[to]) dfs(to);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int msk = 0; msk < ((1 << 20)); ++msk) {
    for (int i = 0; i < (20); ++i) {
      if (msk & (1 << i)) vrj[msk] = i;
    }
  }
  int ttt;
  cin >> ttt;
  while (ttt--) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for (int i = (0); i <= (25); ++i) {
      g[i].clear();
      col[i] = false;
      for (int j = (0); j <= (25); ++j) ug[i][j] = false;
    }
    for (int i = 0; i < (n); ++i) {
      if (a[i] == b[i]) continue;
      g[a[i] - 'a'].push_back(b[i] - 'a');
      g[b[i] - 'a'].push_back(a[i] - 'a');
      ug[a[i] - 'a'][b[i] - 'a'] = true;
    }
    for (int i = 0; i < (20); ++i) {
      qan[i][0] = 0;
      for (int msk = (1); msk <= ((1 << 20) - 1); ++msk) {
        qan[i][msk] = qan[i][msk ^ (1 << vrj[msk])] + ug[vrj[msk]][i];
      }
    }
    for (int v = 0; v < (20); ++v) {
      if (!col[v]) {
        tv.clear();
        dfs(v);
        ans += (int)tv.size() - 1;
        int m = tv.size();
        for (int msk = 0; msk < ((1 << m)); ++msk) {
          pox[msk] = 0;
          for (int i = 0; i < (m); ++i) {
            if (msk & (1 << i)) pox[msk] += (1 << tv[i]);
          }
        }
        dp[0] = 0;
        for (int msk = (1); msk <= ((1 << m) - 1); ++msk) {
          dp[msk] = INT_MAX;
          for (int i = 0; i < (m); ++i) {
            if ((1 << i) & msk) {
              int bruh = dp[msk ^ (1 << i)];
              if (qan[tv[i]][pox[msk ^ (1 << i)]]) bruh++;
              dp[msk] = min(dp[msk], bruh);
            }
          }
        }
        ans += dp[(1 << m) - 1];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
