#include <bits/stdc++.h>
using namespace std;
class dsu {
 public:
  vector<int> p;
  int n;
  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }
  inline int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }
  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};
const int n = 20;
int tt;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> tt;
  while (tt--) {
    int foo;
    string a, b;
    cin >> foo >> a >> b;
    dsu st(n);
    vector<int> take(n);
    for (int i = 0; i < foo; i++) {
      int x = a[i] - 'a';
      int y = b[i] - 'a';
      if (x == y) continue;
      st.unite(x, y);
      take[y] |= 1 << x;
    }
    vector<vector<int>> to_solve(n);
    for (int i = 0; i < n; i++) to_solve[st.get(i)].push_back(i);
    int res = 0;
    for (vector<int> cur : to_solve) {
      if (cur.empty()) continue;
      vector<int> id(n, -1);
      int sz = cur.size();
      for (int i = 0; i < sz; i++) {
        id[cur[i]] = i;
      }
      vector<int> give(sz);
      for (int i = 0; i < n; i++) {
        if (id[i] == -1) continue;
        int x = id[i];
        for (int j = 0; j < n; j++) {
          int y = id[j];
          if (y == -1) continue;
          if ((take[i] >> j) & 1) give[x] |= 1 << y;
        }
      }
      int add = 2 * n - 1;
      vector<bool> dp(1 << sz);
      dp[0] = true;
      for (int mask = 1; mask < (1 << sz); mask++) {
        for (int i = 0; i < sz; i++) {
          if (!((mask >> i) & 1) || give[i] & mask) continue;
          if (dp[mask ^ (1 << i)]) dp[mask] = true;
          break;
        }
        if (dp[mask]) add = min(add, sz - 1 + (sz - __builtin_popcount(mask)));
      }
      res += add;
    }
    cout << res << endl;
  }
  return 0;
}
