#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int inf = 0x3f3f3f3f;
char a[N], b[N];
int n;
int call(int c) {
  int mn = inf;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == b[i]) continue;
    if (a[i] - 'a' == c) {
      if (a[i] > b[i]) return -1;
      mn = min(mn, (b[i] - a[i]));
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] - 'a' == c) {
      if (a[i] < b[i]) {
        a[i] += mn;
      }
    }
  }
  bool flag = 1;
  if (mn == inf) flag = 0;
  return flag;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%s%s", a + 1, b + 1);
    int res = 0;
    int flag = 0;
    for (int i = 0; i <= 19; ++i) {
      int c = call(i);
      if (c == -1) {
        flag = 1;
        break;
      }
      res += c;
    }
    if (flag)
      printf("-1\n");
    else
      printf("%d\n", res);
  }
  return 0;
}
