#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y / 2, x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    set<long long> lol[20];
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    for (long long i = 0; i < (n); ++i) {
      if (a[i] != b[i]) lol[a[i] - 'a'].insert(b[i] - 'a');
    }
    long long ans = 0;
    for (long long i = 0; i < (20); ++i) {
      if (lol[i].size() == 0) continue;
      long long x = *lol[i].begin();
      if (x < i) {
        ans = -1;
        break;
      }
      lol[i].erase(x);
      for (auto v : lol[i]) lol[x].insert(v);
      ans++;
    }
    cout << ans << "\n";
  }
}
