import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = readln.strip;
		auto t = readln.strip;
		if (n.iota.any !(i => s[i] > t[i]))
		{
			writeln (-1);
			continue multitest_loop;
		}
		auto r = s.dup;
		int res = 0;
		auto b = new bool [n];
		foreach (c; 'a'..'u')
		{
			foreach (i; 0..n)
			{
				b[i] = (r[i] == c && r[i] < t[i]);
			}
			if (any (b))
			{
				auto d = n.iota.filter !(i => b[i])
				    .map !(i => t[i]).minElement;
				foreach (i; 0..n)
				{
					if (r[i] == c)
					{
						r[i] = d;
					}
				}
				res += 1;
			}
		}
		writeln (res);
	}
}
