#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s, s1;
    cin >> s >> s1;
    int ans = 0;
    bool bad = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] != s1[i] && s[i] > s1[i]) {
        bad = 1;
        break;
      }
    }
    if (bad) {
      cout << "-1" << endl;
      continue;
    }
    set<int> ms[27];
    for (int i = 0; i < n; ++i) {
      if (s[i] != s1[i]) {
        ms[s[i] - 'a'].insert(s1[i] - 'a');
      }
    }
    for (int i = 0; i < 26; ++i) {
      if (ms[i].empty()) continue;
      int x = *ms[i].begin();
      ++ans;
      for (int j = 0; j < n; ++j) {
        if (s[j] == (char)(i + 'a')) {
          if (s[j] != s1[j]) {
            s[j] = (char)(x + 'a');
            if (s[j] != s1[j]) {
              ms[s[j] - 'a'].insert(s1[j] - 'a');
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
