#include <bits/stdc++.h>   using namespace std;   using gg = long long;   constexpr gg MAX = 1e6 + 5;   constexpr gg mod = 1e9 + 7;   constexpr gg INF = 1e10;   constexpr double thre = 1e-7;   gg ti, ni, mi, ki, di, pi, xi, yi;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ti = 1;     cin >> ti;     while (ti--) {       string a, b;       cin >> ni >> a >> b;       map<char, set<char>> m;       for (gg i = 0; i < ni; ++i) {         if (a[i] != b[i]) {           m[a[i]].insert(b[i]);         }       }       gg ans = 0;       bool f = true;       while (not m.empty()) {         auto& [i, j] = *m.begin();         if (*j.begin() < i) {           f = false;           break;         }         if (j.size() != 1) {           for (auto k = next(j.begin()); k != j.end(); ++k) {             m[*j.begin()].insert(*k);           }         }         m.erase(m.begin());         ans++;       }       cout << (f ? ans : -1) <<   n ;     }     return 0;   }   