#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long mod = 1e9 + 7;
const long double PI = acos(-1);
void solve(int tc) {
  int n, s, mx = 0;
  cin >> n;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < (int)n; ++i) {
    if (a[i] > b[i]) {
      cout << "-1" << endl;
      return;
    }
  }
  for (int i = 'a'; i <= 't'; ++i) {
    for (int j = i + 1; j <= 't'; ++j) {
      s = 0;
      for (int k = 0; k < (int)n; ++k) {
        if (a[k] == i && b[k] == j) {
          s = 1;
          break;
        }
      }
      if (s) {
        for (int k = 0; k < (int)n; ++k) {
          if (a[k] == i && b[k] >= j) {
            a[k] = j;
          }
        }
        ++mx;
      }
    }
  }
  cout << mx << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  for (int t = 1; t <= (int)tc; ++t) {
    solve(t);
  }
  return 0;
}
