#include <bits/stdc++.h>
using namespace std;
const int n = 26;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
char s[111111], t[111111];
int a[111111], b[111111];
int fa[33], len;
void predo() {}
void init() {
  len = read();
  scanf("%s", s + 1);
  for (int i = (int)1; i <= (int)len; i++) a[i] = s[i] - 'a' + 1;
  scanf("%s", t + 1);
  for (int i = (int)1; i <= (int)len; i++) b[i] = t[i] - 'a' + 1;
}
int dsu(int k) {
  if (fa[k] != k) fa[k] = dsu(fa[k]);
  return fa[k];
}
void solve() {
  for (int i = (int)1; i <= (int)len; i++) {
    if (a[i] > b[i]) {
      printf("-1\n");
      return;
    }
  }
  int ans = 0;
  for (int i = (int)1; i <= (int)n; i++) fa[i] = i;
  for (int i = (int)1; i <= (int)len; i++) {
    int p = dsu(a[i]), q = dsu(b[i]);
    if (p != q) {
      fa[p] = q;
      ans++;
    }
  }
  printf("%d\n", ans);
}
int main() {
  predo();
  int cas = read();
  while (cas--) {
    init();
    solve();
  }
  return 0;
}
