#include <bits/stdc++.h>
const double eps = 1e-7, PI = 3.1415926;
const int N = 2e5 + 10;
using namespace std;
int n, q, m, k, x, y, a[N], mx = -1, mn = 1e9, sum, t;
char c[N];
string s, s1, s2;
map<pair<int, char>, int> mp;
vector<int> vec;
int main() {
  cin >> q;
  while (q--) {
    cin >> n;
    cin >> s1 >> s2;
    y = 0;
    mp.clear();
    sum = 0;
    for (int i = 0; i < 20; i++) {
      char v = 'a' + i;
      mn = 1e9;
      int hg = 20;
      while (hg--) {
        mn = 1e9;
        for (int j = 0; j < n; j++) {
          if (s1[j] == v && s2[j] != s1[j]) {
            mn = min(mn, s2[j] - s1[j]);
          }
        }
        for (int j = 0; j < n; j++) {
          if (s1[j] == v && s2[j] != s1[j]) {
            s1[j] += mn;
          }
        }
        if (mn < 0) y = 1;
        if (mn == 1e9)
          break;
        else
          sum++;
      }
    }
    if (!y)
      cout << sum << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
