#include <bits/stdc++.h>
using namespace std;
int g[22][22];
int dp[1100000];
int a[1100000][22];
int b[1100000][22];
int rep[22];
vector<pair<int, int>> vt;
bool debug_ = false;
void gao() {
  int nn = (1 << 20);
  for (int i = 1; i < nn; ++i) {
    int j = 0, jj = 1;
    for (; j < 20; ++j) {
      if ((i >> j) & 1) {
        jj = (1 << j);
        break;
      }
    }
    for (int k = 0; k < 20; ++k) {
      if ((i >> k) & 1) {
        continue;
      }
      a[i][k] = (a[i ^ jj][k] | g[k][j]);
      b[i][k] = (b[i ^ jj][k] | g[j][k]);
    }
  }
  for (int i = 1; i < nn; ++i) {
    vt.clear();
    for (int j = 0; j < 20; ++j) {
      if ((i >> j) & 1) {
        vt.emplace_back(j, (1 << j));
      }
    }
    if (debug_ && i == 3) {
      printf("debug: vt_size %d\n", vt.size());
    }
    if (vt.size() == 1) {
      dp[i] = 0;
      continue;
    }
    dp[i] = 10000;
    for (int j = 0; j < vt.size(); ++j) {
      int k = vt[j].first, ii = (i ^ vt[j].second);
      if (a[ii][k] && b[ii][k]) {
        dp[i] = min(dp[i], dp[ii] + 2);
      } else {
        dp[i] = min(dp[i], dp[ii] + 1);
      }
    }
  }
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < 20; ++j) {
      g[i][j] |= g[j][i];
    }
  }
  for (int k = 0; k < 20; ++k) {
    for (int i = 0; i < 20; ++i) {
      for (int j = 0; j < 20; ++j) {
        g[i][j] |= (g[i][k] & g[k][j]);
      }
    }
  }
  memset(rep, -1, sizeof(rep));
  int ret = 0;
  for (int i = 0; i < 20; ++i) {
    if (rep[i] != -1) {
      continue;
    }
    int msk = 0;
    for (int j = i; j < 20; ++j) {
      if (g[i][j]) {
        rep[j] = i;
        msk |= (1 << j);
      }
    }
    ret += dp[msk];
  }
  cout << ret << endl;
}
char s1[110000];
char s2[110000];
int main() {
  int t, n;
  cin >> t;
  while (t--) {
    memset(g, 0, sizeof(g));
    cin >> n;
    scanf("%s", s1);
    scanf("%s", s2);
    for (int i = 0; i < n; ++i) {
      if (s1[i] != s2[i]) {
        g[s1[i] - 'a'][s2[i] - 'a'] = 1;
      }
    }
    gao();
  }
  return 0;
}
