#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const long long MOD = 1e9 + 7;
set<char> seen;
void solve() {
  int n;
  cin >> n;
  string a;
  string b;
  cin >> a >> b;
  for (int i = 0; i < n; i++) {
    if (a[i] > b[i]) {
      cout << "-1\n";
      return;
    }
  }
  int ans = 0;
  for (char c = 'a'; c <= 't'; c++) {
    char smallest = 'z';
    for (int i = 0; i < n; i++) {
      if (a[i] == c) {
        if (a[i] != b[i]) smallest = min(smallest, b[i]);
      }
    }
    if (smallest != 'z') {
      ans++;
      for (int i = 0; i < n; i++) {
        if (a[i] == c) {
          if (a[i] != b[i]) {
            a[i] = smallest;
          }
        }
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int TC;
  cin >> TC;
  while (TC--) {
    solve();
  }
}
