#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    bool f = false;
    for (int i = 0; i < n; ++i) {
      if (a[i] > b[i]) {
        cout << "-1\n";
        f = true;
        break;
      }
    }
    if (f) continue;
    int ans = 0;
    for (char c = 'a'; c <= 't'; ++c) {
      int cur = 30;
      for (int i = 0; i < n; ++i) {
        if (a[i] == c && b[i] > c) {
          cur = min(b[i] - a[i], cur);
        }
      }
      if (cur != 30) ++ans;
      for (int i = 0; i < n; ++i) {
        if (a[i] == c && b[i] > c) a[i] += cur;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
