#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Edge {
  ll to, cap, rev;
  Edge(ll _to, ll _cap, ll _rev) {
    to = _to;
    cap = _cap;
    rev = _rev;
  }
};
void add_edge(vector<vector<Edge>> &G, ll from, ll to, ll cap, bool revFlag,
              ll revCap) {
  G[from].push_back(Edge(to, cap, (ll)G[to].size()));
  if (revFlag) G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
class UnionFind {
  vector<int> data;
  int num;

 public:
  UnionFind(int size) : data(size, -1), num(size) {}
  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
      num--;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
  int numSet() { return num; }
};
void solve() {
  ll n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  UnionFind uni(26);
  map<ll, ll> mp;
  for (int(i) = (int)(0); i < (int)(n); ++i) {
    if (s[i] == t[i]) continue;
    int ss = s[i] - 'a';
    int tt = t[i] - 'a';
    uni.unionSet(ss, tt);
    mp[ss]++;
    mp[tt]++;
  }
  int m = 0;
  for (auto &i : mp) {
    i.second = m;
    m++;
  }
  vector<ll> out(m, 0), in(m, 0);
  for (int(i) = (int)(0); i < (int)(n); ++i) {
    if (s[i] == t[i]) continue;
    int ss = mp[s[i] - 'a'];
    int tt = mp[t[i] - 'a'];
    out[ss] |= 1LL << tt;
    in[tt] |= 1LL << ss;
  }
  ll all = 1LL << m;
  vector<ll> dp(all, 0);
  dp[0] = 1;
  ll ldag = 1;
  for (int(bit) = (int)(0); bit < (int)(all); ++bit) {
    if (!dp[bit]) continue;
    chmax(ldag, (ll)__builtin_popcountll(bit));
    for (int(i) = (int)(0); i < (int)(m); ++i) {
      if ((bit >> i) & 1) continue;
      if ((bit & in[i]) and (bit & out[i])) continue;
      dp[bit | (1LL << i)] = dp[bit];
    }
  }
  if (m)
    cout << 2 * m - ldag - uni.numSet() + (26 - m) << '\n';
  else
    cout << 0 << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t;
  cin >> t;
  while (t--) solve();
  return 0;
}
