#include <bits/stdc++.h>
using namespace std;
int A[32];
int B[32];
int AA[1 << 20];
int BB[1 << 20];
int R[1 << 20];
int f(int mask) {
  if (mask == 0) return 0;
  int& res = R[mask];
  if (res != -1) return res;
  res = 47;
  int i;
  int all = (1 << 20) - 1;
  int used = all ^ mask;
  int za = (AA[used] | used) == used ? 0 : 1;
  int zb = (BB[used] | used) == used ? 0 : 1;
  for (i = (0); i < (20); ++i)
    if (mask & (1 << i)) {
      int r = f(mask ^ (1 << i)) + max(za, max(zb, (A[i] & used) == 0 ? 0 : 1));
      if (B[i] & (mask ^ (1 << i))) ++r;
      res = min(res, r);
    }
  return res;
}
void solve(int test) {
  int n;
  string a, b;
  cin >> n >> a >> b;
  int i, j;
  memset(A, 0, sizeof(A));
  memset(B, 0, sizeof(B));
  for (i = (0); i < (n); ++i)
    if (a[i] != b[i]) {
      A[a[i] - 'a'] |= 1 << (b[i] - 'a');
      B[b[i] - 'a'] |= 1 << (a[i] - 'a');
    }
  AA[0] = BB[0];
  for (i = (1); i < (1 << 20); ++i) {
    for (j = (0); j < (20); ++j)
      if (i & (1 << j)) break;
    AA[i] = AA[i ^ (1 << j)] | A[j];
    BB[i] = BB[i ^ (1 << j)] | B[j];
  }
  memset(R, -1, sizeof(R));
  cout << f((1 << 20) - 1) << endl;
}
int main() {
  int T = 1, t;
  cin >> T;
  for (t = (0); t < (T); ++t) solve(t);
  return 0;
}
