#include <bits/stdc++.h>
using namespace std;
long long t, n, kol, ans;
bool f;
set<long long> edges[305];
string s, s1;
bool used[305];
void dfs(long long v) {
  ++kol;
  used[v] = true;
  for (auto it : edges[v])
    if (!used[it]) dfs(it);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (long long o = 1; o <= t; ++o) {
    cin >> n;
    cin >> s;
    cin >> s1;
    f = true;
    for (long long i = 0; i < n; ++i)
      if (s1[i] < s[i]) {
        f = false;
        break;
      }
    if (!f) {
      cout << "-1\n";
      continue;
    }
    for (char c = 'a'; c <= 't'; ++c) edges[c].clear(), used[c] = false;
    for (long long i = 0; i < n; ++i)
      if (s[i] != s1[i]) edges[s[i]].insert(s1[i]), edges[s1[i]].insert(s[i]);
    ans = 0;
    for (char c = 'a'; c <= 't'; ++c)
      if (!used[c]) {
        kol = 0;
        dfs((long long)c);
        ans += (kol - 1);
      }
    cout << ans << '\n';
  }
  return 0;
}
