#include <bits/stdc++.h>
using namespace std;
int n;
string a, b;
vector<int> adj[25];
bool vis[25];
void dfs(int s) {
  vis[s] = 1;
  for (auto i : adj[s])
    if (!vis[i]) dfs(i);
}
void solve() {
  bool f = 0;
  for (long long i = 0; i < (n); ++i)
    if (a[i] != b[i]) f = 1;
  if (!f) {
    cout << 0;
    return;
  }
  for (long long i = 0; i < (n); ++i) {
    if (a[i] != b[i]) {
      if (a[i] > b[i]) {
        cout << -1;
        return;
      }
      adj[a[i] - 'a'].push_back(b[i] - 'a');
      adj[b[i] - 'a'].push_back(a[i] - 'a');
    }
  }
  int ans = 20;
  for (long long i = 0; i < (20); ++i) {
    if (!vis[i]) dfs(i), ans--;
  }
  cout << ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  cin >> test;
  while (test--) {
    cin >> n;
    cin >> a >> b;
    for (long long i = 0; i < (25); ++i) adj[i].clear(), vis[i] = 0;
    solve();
    cout << "\n";
  }
}
