#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int INF = 1e8 + 10;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    bool f = 1;
    int arr = 0;
    for (char c = 'a'; c <= 't'; c++) {
      vector<bool> cnt(20, 0);
      for (int i = 0; i < n; i++) {
        if (s[i] == t[i]) continue;
        if (t[i] == c && s[i] > c) f = 0;
        if (t[i] == c) cnt[s[i] - 'a'] = 1;
      }
      for (int i = 0; i < n; i++) {
        if (s[i] != t[i] && cnt[s[i] - 'a']) s[i] = c;
      }
      for (int i = 0; i < 20; i++) arr += cnt[i];
    }
    cout << (f ? arr : -1) << '\n';
  }
}
