#include <bits/stdc++.h>
using namespace std;
int t;
int mp[21][21];
void print() {
  for (int i = 0; i < 21; i++) {
    for (int j = 0; j < 21; j++) {
      cout << mp[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
void solve() {
  int n;
  string a, b;
  cin >> n >> a >> b;
  int c = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < b[i]) {
      mp[a[i] - 'a'][b[i] - 'a']++;
      sum++;
    } else if (a[i] == b[i])
      continue;
    else {
      cout << -1 << endl;
      return;
    }
  }
  for (int i = 0; i < 21; i++) {
    int j;
    for (j = 0; j < 21; j++) {
      if (mp[i][j] && sum != 0) {
        c++;
        break;
      }
    }
    for (int k = 0; k < 21; k++) {
      mp[j][k] += mp[i][k];
      sum -= mp[k][k];
      mp[k][k] = 0;
    }
  }
  cout << c << endl;
}
void clean() {
  for (int i = 0; i < 21; i++) {
    for (int j = 0; j < 21; j++) {
      mp[i][j] = 0;
    }
  }
}
int main() {
  for (cin >> t; t; t--) {
    solve();
    clean();
  }
}
