#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2>& a, const pair<T1, T2>& b);
template <typename T1, typename T2>
pair<T1, T2>& operator+=(pair<T1, T2>& a, const pair<T1, T2>& b);
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2>& p);
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2>& a, const pair<T1, T2>& b);
template <typename T1, typename T2>
pair<T1, T2>& operator-=(pair<T1, T2>& a, const pair<T1, T2>& b);
template <typename T1, typename T2, typename T3>
pair<T1, T2> operator*(const pair<T1, T2>& p, T3 mult);
template <typename T1, typename T2, typename T3>
pair<T1, T2> operator*(T3 mult, const pair<T1, T2>& p);
template <int MOD = 7>
struct Modular {
  int value;
  static const int MOD_VAL = MOD;
  Modular(long long = 0);
  Modular(long long, long long);
  Modular exp(Modular, long long);
  Modular inv();
  Modular& operator+=(const Modular&);
  Modular& operator-=(const Modular&);
  Modular& operator*=(const Modular&);
  Modular& operator/=(const Modular&);
  Modular& operator++();
  Modular& operator--();
  template <int MOD_>
  friend Modular<MOD> operator+(const Modular&, const Modular&);
  template <int MOD_>
  friend Modular<MOD> operator-(const Modular&, const Modular&);
  template <int MOD_>
  friend Modular operator-(const Modular&);
  template <int MOD_>
  friend Modular operator*(const Modular&, const Modular&);
  template <int MOD_>
  friend Modular operator/(const Modular&, const Modular&);
  template <int MOD_>
  friend ostream& operator<<(ostream&, const Modular&);
  operator int();
  bool operator==(const Modular&);
  bool operator!=(const Modular&);
};
template <typename T>
T scanf_t();
template <>
int scanf_t();
template <>
long long scanf_t();
template <>
double scanf_t();
template <>
long double scanf_t();
template <>
char scanf_t();
template <>
float scanf_t();
template <>
string scanf_t();
string scanf_t(int);
int (*si)() = scanf_t<int>;
long long (*sl)() = scanf_t<long long>;
double (*sdb)() = scanf_t<double>;
long double (*sldb)() = scanf_t<long double>;
char (*sc)() = scanf_t<char>;
float (*sf)() = scanf_t<float>;
string (*ss)(int) = scanf_t;
template <typename T>
void printf_t(const T&, char = '\n', FILE* = stdout);
template <typename T>
void printf_t(const T*, char = '\n', FILE* = stdout);
template <typename T>
void printf_t(T*, char = '\n', FILE* = stdout);
template <typename T1, typename T2>
void printf_t(const pair<T1, T2>&, char = '\n', FILE* = stdout);
template <typename T, typename Alloc,
          template <typename, typename> class Container>
void printf_t(const Container<T, Alloc>&, char = '\n', FILE* = stdout);
void print();
template <typename T>
void print(const T&);
template <typename T, typename... Args>
void print(const T&, const Args&...);
void _dbg();
template <typename T>
void _dbg(const T&);
template <typename T, typename... Args>
void _dbg(const T&, const Args&...);
template <typename... Args>
void dbg(const Args&...);
template <typename T>
void in(T*, int);
template <typename T, typename Alloc,
          template <typename, typename> class Container>
void sv(Container<T, Alloc>&, int);
template <typename T, typename Alloc>
void sv(vector<T, Alloc>&, int);
template <typename It>
void out(It, It, char = '\n', char = ' ', FILE* = stdout);
template <typename Container>
void pv(const Container&, char = '\n', char = ' ', FILE* = stdout);
void pi(const int&, char = '\n');
void pl(const long long&, char = '\n');
void pd(const double&, char = '\n');
void pld(const long double&, char = '\n');
void pf(const float&, char = '\n');
void pc(const char&, char = '\n');
void ps(const string&, char = '\n');
long long russian(long long, long long, long long);
long long fastpow(long long, long long, long long);
long long slowpow(long long, long long, long long);
long long extgcd(long long, long long);
long long _gcd(long long, long long);
long long _lcm(long long, long long);
long long _inv(long long, long long);
template <typename T>
void print_bits(T x, int = 0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e9;
const long long LINF = 1e18;
const long long M = 1e9 + 7;
const int C = 20;
vector<int> G[C], cur;
int masks[C];
bool dp[1 << C], vis[C];
int mask;
void dfs(int v) {
  vis[v] = true;
  mask |= 1 << v;
  cur.push_back(v);
  for (auto& s : G[v])
    if (!vis[s]) dfs(s);
}
int count() {
  vector<int> sub;
  for (int m = (mask); m; m = (m - 1) & (mask)) sub.push_back(m);
  reverse((sub).begin(), (sub).end());
  int res = 0;
  for (auto& m : sub) {
    for (auto& v : cur)
      if (m & 1 << v) dp[m] |= dp[m ^ 1 << v] & ((m & masks[v] & mask) == 0);
    if (dp[m]) res = max(res, __builtin_popcount(m));
  }
  return res;
}
int solve() {
  int n = si();
  string s = scanf_t<string>();
  string t = scanf_t<string>();
  auto get = [](char c) { return c - 'a'; };
  for (int i = 0; i < (n); ++i)
    if (s[i] != t[i]) {
      int a = get(s[i]);
      int b = get(t[i]);
      G[a].push_back(b);
      G[b].push_back(a);
      masks[a] |= 1 << b;
    }
  int res = 0;
  dp[0] = true;
  for (int i = 0; i < (C); ++i)
    if (!vis[i]) {
      mask = 0;
      cur.clear();
      dfs(i);
      int tmp = count();
      res += 2 * (int)(cur).size() - 1 - tmp;
    }
  fill(vis, vis + C, false);
  fill(masks, masks + C, 0);
  fill(dp, dp + (1 << C), false);
  for (int i = 0; i < (C); ++i) G[i].clear();
  return res;
}
int main() {
  int t = si();
  while (t--) print(solve());
  return 0;
}
template <>
int scanf_t() {
  int x;
  scanf("%d", &x);
  return x;
}
template <>
long long scanf_t() {
  long long x;
  scanf("%lld", &x);
  return x;
}
template <>
double scanf_t() {
  double x;
  scanf("%lf", &x);
  return x;
}
template <>
long double scanf_t() {
  long double x;
  scanf("%Lf", &x);
  return x;
}
template <>
char scanf_t() {
  char x;
  scanf(" %c", &x);
  return x;
}
template <>
float scanf_t() {
  float x;
  scanf("%f", &x);
  return x;
}
string scanf_t(int n) {
  char x[n + 7];
  scanf("%s", x);
  return string(x);
}
template <>
void printf_t(const int& x, char end, FILE* out) {
  fprintf(out, "%d%c", x, end);
}
template <>
void printf_t(const long long& x, char end, FILE* out) {
  fprintf(out, "%lld%c", x, end);
}
template <>
void printf_t(const double& x, char end, FILE* out) {
  fprintf(out, "%.8lf%c", x, end);
}
template <>
void printf_t(const long double& x, char end, FILE* out) {
  fprintf(out, "%.10Lf%c", x, end);
}
template <>
void printf_t(const float& x, char end, FILE* out) {
  fprintf(out, "%f%c", x, end);
}
template <>
void printf_t(const char& x, char end, FILE* out) {
  fprintf(out, "%c%c", x, end);
}
template <>
void printf_t(const string& x, char end, FILE* out) {
  fprintf(out, "%s%c", x.c_str(), end);
}
template <>
void printf_t(const char* x, char end, FILE* out) {
  fprintf(out, "%s%c", x, end);
}
template <>
void printf_t(char* x, char end, FILE* out) {
  fprintf(out, "%s%c", x, end);
}
template <>
void printf_t(const Modular<>& x, char end, FILE* out) {
  printf_t(x.value, end, out);
}
template <>
void printf_t(const uint64_t& x, char end, FILE* out) {
  fprintf(out, "%lu%c", x, end);
}
template <>
void printf_t(const uint32_t& x, char end, FILE* out) {
  fprintf(out, "%u%c", x, end);
}
template <>
void printf_t(const bool& x, char end, FILE* out) {
  fprintf(out, "%d%c", x, end);
}
template <>
void printf_t(const long& x, char end, FILE* out) {
  fprintf(out, "%ld%c", x, end);
}
template <typename T1, typename T2>
void printf_t(const pair<T1, T2>& x, char end, FILE* out) {
  fprintf_t(x.first, ' ', out);
  printf_t(x.second, end, out);
}
template <typename T, typename Alloc,
          template <typename, typename> class Container>
void printf_t(const Container<T, Alloc>& v, char end, FILE* out) {
  pv(v, end, ' ', out);
}
template <>
string scanf_t() {
  int size = 8;
  char* s = (char*)malloc(size * sizeof(char));
  char c;
  while (isspace(c = getchar()))
    ;
  *s = c;
  int i = 1;
  while (!isspace(c = getchar())) {
    s[i++] = c;
    if (i == size) s = (char*)realloc(s, size *= 2);
  }
  s[i] = '\0';
  string res(s);
  free(s);
  return res;
}
void print() { printf("\n"); }
template <typename T>
void print(const T& last) {
  printf_t(last, '\n');
}
template <typename T, typename... Args>
void print(const T& first, const Args&... rest) {
  printf_t(first, ' ');
  print(rest...);
}
void _dbg() {}
template <typename T>
void _dbg(const T& last) {
  printf_t(last, ' ', stderr);
}
template <typename T, typename... Args>
void _dbg(const T& first, const Args&... rest) {
  printf_t(first, ' ', stderr);
  _dbg(rest...);
}
template <typename... Args>
void dbg(const Args&... args) {
  fprintf(stderr, "[ ");
  _dbg(args...);
  fprintf(stderr, "]\n");
}
template <typename T>
void in(T* begin, int n) {
  while (n--) *begin++ = scanf_t<T>();
}
template <typename T, typename Alloc,
          template <typename, typename> class Container>
void sv(Container<T, Alloc>& v, int n) {
  auto it = std::back_inserter(v);
  while (n--) *it = scanf_t<T>();
}
template <typename T, typename Alloc>
void sv(vector<T, Alloc>& v, int n) {
  v.reserve(n);
  auto it = std::back_inserter(v);
  while (n--) *it = scanf_t<T>();
}
template <typename It>
void out(It begin, It end, char endl, char sep, FILE* outs) {
  if (begin == end) {
    fprintf(outs, "%c", endl);
    return;
  }
  while (next(begin) != end) printf_t(*begin++, sep, outs);
  printf_t(*begin, endl, outs);
}
template <typename Container>
void pv(const Container& v, char end, char sep, FILE* outs) {
  out((v).begin(), (v).end(), end, sep, outs);
}
void pi(const int& x, char end) { printf_t(x, end); }
void pl(const long long& x, char end) { printf_t(x, end); }
void pd(const double& x, char end) { printf_t(x, end); }
void pld(const long double& x, char end) { printf_t(x, end); }
void pf(const float& x, char end) { printf_t(x, end); }
void pc(const char& x, char end) { printf_t(x, end); }
void ps(const string& x, char end) { printf_t(x, end); }
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2>& a, const pair<T1, T2>& b) {
  return {a.first + b.first, a.second + b.second};
}
template <typename T1, typename T2>
pair<T1, T2>& operator+=(pair<T1, T2>& a, const pair<T1, T2>& b) {
  a.first += b.first;
  a.second += b.second;
  return a;
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2>& p) {
  return {-p.first, -p.second};
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2>& a, const pair<T1, T2>& b) {
  return {a.first - b.first, a.second - b.second};
}
template <typename T1, typename T2>
pair<T1, T2>& operator-=(pair<T1, T2>& a, const pair<T1, T2>& b) {
  a.first -= b.first;
  a.second -= b.second;
  return a;
}
template <typename T1, typename T2, typename T3>
pair<T1, T2> operator*(const pair<T1, T2>& p, T3 mult) {
  return {p.first * mult, p.second * mult};
}
template <typename T1, typename T2, typename T3>
pair<T1, T2> operator*(T3 mult, const pair<T1, T2>& p) {
  return {p.first * mult, p.second * mult};
}
long long russian(long long a, long long k, long long m) {
  long long res = 0LL;
  while (k) {
    if (k & 1LL) res = (res + a) % m;
    a = (a + a) % m;
  }
  return res;
}
long long fastpow(long long a, long long k, long long m) {
  long long res = 1LL;
  while (k) {
    if (k & 1LL) res = (res * a) % m;
    a = (a * a) % m;
    k >>= 1;
  }
  return res;
}
long long slowpow(long long a, long long k, long long m) {
  long long res = 1LL;
  while (k) {
    if (k & 1LL) res = russian(res, a, m);
    a = russian(a, a, m);
    k >>= 1;
  }
  return res;
}
long long _gcd(long long a, long long b) {
  while (b) swap(a %= b, b);
  return a;
}
long long _lcm(long long a, long long b) { return a / _gcd(a, b) * b; }
long long _inv(long long a, long long p) { return fastpow(a, p - 2, p); }
long long extgcd(long long a, long long b, long long& k, long long& l) {
  if (b == 0) {
    k = 1;
    l = 0;
    return a;
  }
  long long res = extgcd(b, a % b, l, k);
  l -= a / b * k;
  return res;
}
template <typename T>
void print_bits(T x, int force_len) {
  assert(0 <= force_len && force_len <= 64);
  static char s[64];
  int i = 63;
  if (force_len)
    while (force_len--) s[i--] = '0' + (x & 1), x >>= 1;
  else
    while (x) s[i--] = '0' + (x & 1), x >>= 1;
  printf("%s\n", s + i + 1);
}
template <int MOD>
Modular<MOD>::Modular(long long v) {
  value = v % MOD;
  if (value < 0) value += MOD;
}
template <int MOD>
Modular<MOD>::Modular(long long a, long long b) : value(0) {
  *this += a;
  *this /= b;
}
template <int MOD>
Modular<MOD>& Modular<MOD>::operator+=(const Modular& o) {
  value += o.value;
  if (value >= MOD) value -= MOD;
  return *this;
}
template <int MOD>
Modular<MOD>& Modular<MOD>::operator-=(const Modular& o) {
  value -= o.value;
  if (value < 0) value += MOD;
  return *this;
}
template <int MOD>
Modular<MOD>& Modular<MOD>::operator*=(const Modular& o) {
  value = (long long)value * o.value % MOD;
  return *this;
}
template <int MOD>
Modular<MOD>& Modular<MOD>::operator/=(const Modular& o) {
  return *this *= o.inv();
}
template <int MOD>
Modular<MOD>& Modular<MOD>::operator++() {
  return *this += 1;
}
template <int MOD>
Modular<MOD>& Modular<MOD>::operator--() {
  return *this -= 1;
}
template <int MOD>
Modular<MOD> exp(Modular<MOD> a, long long k) {
  Modular<MOD> res = 1;
  while (k) {
    if (k & 1LL) res *= a;
    a *= a;
    k >>= 1;
  }
  return res;
}
template <int MOD>
Modular<MOD> Modular<MOD>::inv() {
  return exp(value, MOD - 2);
}
template <int MOD>
Modular<MOD> operator+(const Modular<MOD>& a, const Modular<MOD>& b) {
  return {a.value + b.value};
}
template <int MOD>
Modular<MOD> operator-(const Modular<MOD>& a, const Modular<MOD>& b) {
  return a -= b;
}
template <int MOD>
Modular<MOD> operator-(const Modular<MOD>& a) {
  return 0 - a;
}
template <int MOD>
Modular<MOD> operator*(const Modular<MOD>& a, const Modular<MOD>& b) {
  return a *= b;
}
template <int MOD>
Modular<MOD> operator/(const Modular<MOD>& a, const Modular<MOD>& b) {
  return a /= b;
}
template <int MOD>
ostream& operator<<(ostream& os, const Modular<MOD>& m) {
  os << m.value;
  return os;
}
template <int MOD>
Modular<MOD>::operator int() {
  return value;
}
template <int MOD>
bool Modular<MOD>::operator==(const Modular& o) {
  return value == o.value;
}
template <int MOD>
bool Modular<MOD>::operator!=(const Modular& o) {
  return value != o.value;
}
