#include <bits/stdc++.h>
using namespace std;
int f[22][22];
int n;
string s, t;
bool vis[22];
int a[214514];
int dfs(int u) {
  vis[u] = 1;
  int sum = 0;
  for (int i = 0; i < 20; i++)
    if (f[u][i] && !vis[i]) {
      sum += dfs(i) + 1;
    }
  return sum;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    memset(f, 0, sizeof(f));
    memset(vis, 0, sizeof(vis));
    cin >> n;
    cin >> s;
    cin >> t;
    bool fl = 0;
    for (int i = 0; i < n; i++)
      if (s[i] > t[i]) {
        fl = 1;
        break;
      }
    if (fl) {
      cout << -1 << "\n";
      continue;
    }
    for (int i = 0; i < n; i++) {
      a[i] = t[i] - s[i];
      f[s[i] - 'a'][t[i] - 'a'] = f[t[i] - 'a'][s[i] - 'a'] = 1;
    }
    int ans = 0;
    for (int i = 0; i < 20; i++)
      if (!vis[i]) {
        ans += dfs(i);
      }
    cout << ans << "\n";
  }
  return 0;
}
