#include <bits/stdc++.h>
using namespace std;
void tmkc() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
}
int main() {
  tmkc();
  int t;
  cin >> t;
  while (t--) {
    long long n, i, j, f = 1, c = 0, r = 0;
    cin >> n;
    string a, b;
    cin >> a >> b;
    char p, x = 'z';
    for (i = 0; i < n; i++) {
      if (a[i] - 'a' > b[i] - 'a') f = 0;
    }
    for (i = 0; i < 20; i++) {
      p = 'a' + i;
      bool bl = 0;
      for (j = 0; j < n; j++) {
        if (a[j] == p) {
          if (a[j] != b[j]) {
            x = min(x, b[j]);
            bl = 1;
          }
        }
      }
      if (bl) {
        bool bll = 0;
        for (j = 0; j < n; j++) {
          if (a[j] == p) {
            if (a[j] != b[j]) {
              a[j] = x;
              bll = 1;
            }
          }
        }
        if (bll) r++;
        x = 'z';
      }
    }
    if (!f)
      cout << "-1";
    else
      cout << r;
    cout << endl;
  }
}
