#include <bits/stdc++.h>
using namespace std;
class DSU {
 public:
  long long int n;
  vector<long long int> par;
  DSU(int _n) : n(_n) {
    par.resize(n);
    iota(par.begin(), par.end(), 0);
  }
  inline long long int get(long long int x) {
    return (x == par[x]) ? x : (par[x] = get(par[x]));
  }
  inline bool put(long long int x, long long int y) {
    x = get(x);
    y = get(y);
    if (x == y) return false;
    par[x] = y;
    return true;
  }
};
void test_case() {
  long long int len;
  cin >> len;
  string a, b;
  cin >> a >> b;
  long long int n = 20;
  DSU d(n);
  for (long long int i = 0; i < len; i++) d.put((a[i] - 'a'), (b[i] - 'a'));
  vector<vector<long long int>> comps(n);
  for (long long int i = 0; i < n; i++) comps[d.get(i)].push_back(i);
  vector<long long int> mask(n, 0);
  for (long long int i = 0; i < len; i++)
    mask[b[i] - 'a'] |= (1 << (a[i] - 'a'));
  long long int ans = 0;
  for (auto& comp : comps) {
    long long int cnt = comp.size();
    if (!cnt) continue;
    vector<long long int> new_mask(cnt);
    for (long long int i = 0; i < cnt; i++) {
      for (long long int j = 0; j < cnt; j++) {
        if (i == j) continue;
        if (mask[comp[i]] & (1 << comp[j])) new_mask[i] |= (1 << j);
      }
    }
    vector<long long int> dp((1 << cnt), 0);
    for (long long int i = 0; i < dp.size(); i++) {
      for (long long int j = 0; j < cnt; j++) {
        if (i & (1 << j)) continue;
        long long int ft = dp[i];
        if ((new_mask[j] & i) == new_mask[j]) ft++;
        dp[i | (1 << j)] = max(dp[i | (1 << j)], ft);
      }
    }
    ans += 2 * cnt - 1 - dp.back();
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    test_case();
    cout << endl;
  }
  return 0;
}
