#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 2e5 + 5;   const double pi = acos(-1.0);   long long addM(long long a, long long b) { return (a + b) % MOD; }   long long multM(long long a, long long b) { return (a * b) % MOD; }   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res *= a;       a *= a;       b >>= 1;     }     return res;   }   long long ModInverse(long long n) { return binpow(n, MOD - 2); }   vector<long long> findFact() {     vector<long long> fact(N);     fact[0] = 1;     for (long long i = 1; i <= N; i++) {       fact[i] = multM(i, fact[i - 1]);     }     return fact;   }   long long ncr(long long n, long long r) {     vector<long long> fact = findFact();     return ((fact[n] * ModInverse(fact[n - r])) % MOD * ModInverse(fact[r])) %            MOD;   }   vector<bool> findPrime() {     vector<bool> is_prime(N + 1, true);     is_prime[0] = false;     is_prime[1] = false;     for (long long i = 2; i <= N; i++) {       if (is_prime[i] && i * i <= N) {         for (long long j = i * i; j <= N; j += i) is_prime[j] = false;       }     }     return is_prime;   }   vector<bool> segmentedSieveNoPreGen(long long L, long long R) {     vector<bool> isPrime(R - L + 1, true);     long long lim = sqrt(R);     for (long long i = 2; i <= lim; ++i)       for (long long j = max(i * i, (L + i - 1) / i * i); j <= R; j += i)         isPrime[j - L] = false;     if (L == 1) isPrime[0] = false;     return isPrime;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt;     cin >> tt;     while (tt--) {       long long n;       cin >> n;       string x, y;       cin >> x >> y;       bool check = true;       for (long long i = 0; i < n; i++) {         if (x[i] > y[i]) {           check = false;         }       }       if (check) {         long long ans = 0;         for (char c =  a ; c <=  z ; c++) {           char mn =  z ;           bool check = false;           for (long long i = 0; i < n; i++) {             if (x[i] == c && x[i] != y[i]) {               check = true;               mn = min(mn, y[i]);             }           }           for (long long i = 0; i < n; i++) {             if (x[i] == c && x[i] != y[i]) {               x[i] = mn;             }           }           if (check) ans++;         }         cout << ans <<   n ;       } else {         cout <<  -1 n ;       }     }     return 0;   }   