#include <bits/stdc++.h>
using namespace std;
long ar[21];
long root(long first) {
  while (first != ar[first]) {
    ar[first] = ar[ar[first]];
    first = ar[first];
  }
  return first;
}
void _union(long first, long second) { ar[root(first)] = root(second); }
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long t;
  cin >> t;
  while (t--) {
    long n;
    string first, second;
    cin >> n >> first >> second;
    long flag = 1, ans = 0;
    for (long i = 0; i < 20; i++) ar[i] = i;
    for (long i = 0; flag && i < n; i++) {
      long tmp1 = first[i] - 'a', tmp2 = second[i] - 'a';
      if (tmp1 > tmp2) flag = 0;
      if (root(tmp1) != root(tmp2)) {
        _union(tmp1, tmp2);
        ++ans;
      }
    }
    if (!flag) ans = -1;
    cout << ans << "\n";
  }
  return 0;
}
