You are given two strings A and B of length N consisting of lowercase English letters. Your objective is to make both the strings equal.

You can apply one of the following 2 operations at each index i:
Convert char A_{i} to B_{i} by doing right cyclic shift of character A_{i}. This increases your score by amount equal to cyclic shifts done.
Convert char B_{i} to A_{i} by doing right cyclic shift of character B_{i}. This decreases your score by amount equal to cyclic shifts done.

Your starting score is zero.  
If the operations are applied optimally, find the minimum [absolute] score possible after making both the strings equal.

Note: A single right cyclic shift converts one character to the next in alphabetical order, except for z which goes to a. That is, the sequence looks like

a \to b \to c \to \ldots \to y \to z \to a \to b \to \ldots

So, for example converting a to e requires 4 right cyclic shifts, and converting k to i requires 24.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains one integer N — the length of strings A and B.
- The second line contains string A.
- The third line contains string B.

------ Output Format ------ 

For each test case, output on a new line the minimum absolute score possible after making both the strings equal.

------ Constraints ------ 

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{5}$
- Both strings $A$ and $B$ have same length $N$ and contain only lowercase English letters.
- The sum of $N$ over all test cases won't exceed $10^{5}$.

----- Sample Input 1 ------ 
4
3
abb
baz
3
zzc
aaa
4
fxbs
dkrc
5
eaufq
drtkn

----- Sample Output 1 ------ 
2
0
11
9

----- explanation 1 ------ 
Test case $1$: The minimum *absolute* score can be obtained as follows:
- Apply operation $1$ at position $1$, converting $a$ to $b$ for a cost of $+1$.
- Apply operation $2$ at position $2$, converting $a$ to $b$ for a cost of $-1$.
- Apply operation $2$ at position $3$, converting $z$ to $b$ for a cost of $-2$.

The score is then $1 -1 -2 = -2$, with absolute value $2$. This is the lowest possible absolute value attainable.

Test case $2$: Apply operations as follows:
- Operation $1$ at index $1$, $z\to a$ for a cost of $+1$
- Operation $1$ at index $2$, $z\to a$ for a cost of $+1$
- Operation $2$ at index $3$, $a\to c$ for a cost of $-2$

This gives us a final score of $1 + 1 - 2 = 0$, which has absolute value $0$. It is not possible to do better than this.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Data structures


Solutions:
T = int(input())
for tc in range(T):
	n = int(input())
	a_arr = input()
	b_arr = input()
	score = 0
	baseline = ord('a') - 1
	for i in range(n):
		a_code = ord(a_arr[i]) - baseline
		b_code = ord(b_arr[i]) - baseline
		score += a_code - b_code + 26
	score = score % 26
	score = min(score, 26 - score)
	print(score)


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	value = 0
	for i in range(len(a)):
		value += ord(a[i]) - ord(b[i])
	value = value % 26
	print(min(abs(value), abs(value - 26)))


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	c = 0
	for i in range(n):
		x = ord(a[i]) - ord(b[i])
		if x <= 26:
			c += 26
		c += x
	print(min(26 - c % 26, c % 26))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	dp = [0] * n
	ans = 0
	for i in range(n):
		dp[i] = dp[i - 1]
		if a[i] != b[i]:
			dp[i] += (ord(a[i]) - ord(b[i])) % 26
	ans = dp[-1] % 26
	sd = abs(ans) % 26
	print(min(sd, 26 - sd))


from string import ascii_lowercase
l = {letter: index for (index, letter) in enumerate(ascii_lowercase, start=1)}

def solution(A, B):
	sum_ = 0
	for i in range(len(A)):
		sum_ += l[A[i]] - l[B[i]]
		sum_ %= 26
	return min(sum_, abs(26 - sum_))
t = int(input())
while t:
	t -= 1
	_ = input()
	A = input()
	B = input()
	print(solution(A, B))


for i in range(int(input())):
	n = int(input())
	x = input()
	y = input()
	s = 0
	for i in range(n):
		if x[i] > y[i]:
			up = 122 - ord(x[i]) + ord(y[i]) - 96
			down = ord(x[i]) - ord(y[i])
		elif x[i] < y[i]:
			up = ord(y[i]) - ord(x[i])
			down = 122 - ord(y[i]) + ord(x[i]) - 96
		else:
			continue
		if abs(s + up) < abs(s - down):
			s += up
		else:
			s -= down
	print(abs(s))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	score = 0
	for i in range(n):
		if a[i] < b[i]:
			score += ord(b[i]) - ord(a[i])
		else:
			score += 26 - (ord(a[i]) - ord(b[i]))
	sub = score // 26
	print(min(score - 26 * sub, -1 * (score - 26 * (sub + 1))))


t = int(input())
while t != 0:
	n = int(input())
	a = input()
	b = input()
	c = 0
	for i in range(0, n):
		k = ord(a[i]) - ord(b[i])
		if k < 0:
			k += 26
		c += k
	print(min(c % 26, 26 - c % 26))
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	str1 = input()
	str2 = input()
	count = 0
	for j in range(n):
		if ord(str1[j]) > ord(str2[j]):
			val = 26 + ord(str2[j]) - ord(str1[j])
			count += val
		else:
			val = ord(str2[j]) - ord(str1[j])
			count += val
	count = min(abs(count % 26 - 26), count % 26)
	print(count)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input()
	b = input()
	y = 0
	z = 0
	for i in range(n):
		x = ord(b[i]) - ord(a[i])
		y += x
	ans = abs(y)
	for i in range(n):
		ans = min(ans, abs(y - 26 * (i + 1)))
		ans = min(ans, abs(y + 26 * (i + 1)))
	print(ans)


count = int(input())
c = 0
while c < count:
	l = int(input())
	s1 = input()
	s2 = input()
	j = 0
	s = 0
	while j < l:
		a2b = ord(s2[j]) - ord(s1[j])
		if a2b < 0:
			a2b = (a2b + 26) % 26
		b2a = ord(s1[j]) - ord(s2[j])
		if b2a < 0:
			b2a = (b2a + 26) % 26
		b2a = -b2a
		if abs(s + a2b) < abs(s + b2a):
			s = s + a2b
		else:
			s = s + b2a
		j = j + 1
	print(abs(s))
	c = c + 1


t = int(input())
for _ in range(t):
	N = int(input())
	a = input()
	b = input()
	l = []
	alph = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(N):
		a1 = alph.find(a[i]) + 1
		b1 = alph.find(b[i]) + 1
		c = b1 - a1
		if c < 0:
			c += 26
		l.append(c)
	add = sum(l)
	add_l = [add]
	for i in range(N):
		add -= 26
		add_l.append(abs(add))
	print(min(add_l))


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	sum = 0
	for (e1, e2) in zip(a, b):
		if ord(e1) < ord(e2):
			pos = ord(e2) - ord(e1)
			neg = 26 - pos
		else:
			neg = ord(e1) - ord(e2)
			pos = 26 - neg
		if abs(sum + pos) < abs(sum - neg):
			sum = sum + pos
		else:
			sum = sum - neg
	print(abs(sum))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	sum = 0
	for (e1, e2) in zip(a, b):
		if ord(e1) < ord(e2):
			positive = ord(e2) - ord(e1)
			negative = 26 - positive
		else:
			negative = ord(e1) - ord(e2)
			positive = 26 - negative
		if abs(sum + positive) < abs(sum - negative):
			sum = sum + positive
		else:
			sum = sum - negative
	print(abs(sum))


for _ in range(int(input())):
	N = int(input())
	x = input()
	y = input()
	sum = 0
	for (xi, yi) in zip(x, y):
		if ord(xi) < ord(yi):
			op1 = ord(yi) - ord(xi)
			op2 = op1 - 26
		else:
			op2 = ord(yi) - ord(xi)
			op1 = op2 + 26
		if abs(sum + op1) < abs(sum + op2):
			sum = sum + op1
		else:
			sum = sum + op2
	print(abs(sum))


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(input())
	B = list(input())
	score = 0
	for i in range(N):
		score += ord(B[i]) - ord(A[i])
	min_score = abs(score) % 26
	print(min(min_score, abs(min_score - 26)))


def rs(x, y):
	return ord(y) - ord(x)
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	s = 0
	for i in range(n):
		s += rs(a[i], b[i])
	v = s // 26
	print(min(s - 26 * v, 26 * (v + 1) - s))


for test in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	arr1 = [ord(i) - 97 for i in s1]
	arr2 = [ord(i) - 97 for i in s2]
	score = 0
	for (i, j) in zip(arr1, arr2):
		(cost1, cost2) = (0, 0)
		if i <= j:
			cost1 = j - i
			cost2 = -(26 - j + i)
		else:
			cost1 = 26 - i + j
			cost2 = j - i
		cost1 += score
		cost2 += score
		if abs(cost1) < abs(cost2):
			score = cost1
		else:
			score = cost2
	print(abs(score))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	i = 0
	j = 0
	k = 0
	for i in range(n):
		if ord(a[i]) > ord(b[i]):
			j = 26 - (ord(a[i]) - ord(b[i]))
			k += j
		else:
			d = ord(b[i]) - ord(a[i])
			k += d
	r = min(abs(k % 26 - 26), k % 26)
	print(r)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	c1 = 0
	c2 = 0
	score = 0
	for i in range(n):
		x = ord(a[i])
		y = ord(b[i])
		if x <= y:
			c1 = y - x
			c2 = c1 - 26
		else:
			c1 = y - x
			c2 = 26 + c1
		if abs(score + c1) < abs(score + c2):
			score = score + c1
		else:
			score = score + c2
	print(abs(score))


T = int(input())
for _ in range(T):
	N = int(input())
	S1 = input()
	S2 = input()
	score = 0
	for i in range(N):
		(c1, c2) = (S1[i], S2[i])
		(cost1, cost2) = (0, 0)
		if c1 <= c2:
			cost1 = ord(c2) - ord(c1)
			cost2 = -(26 - (ord(c2) - ord(c1)))
		else:
			cost2 = -(ord(c1) - ord(c2))
			cost1 = 26 - (ord(c1) - ord(c2))
		if abs(cost1 + score) < abs(cost2 + score):
			score = cost1 + score
		else:
			score = cost2 + score
	print(abs(score))


def min_abs_scr(n, a, b):
	cnt = 0
	for i in range(n):
		if a[i] != b[i]:
			a_pos = alphabet.rfind(a[i]) + 1
			b_pos = alphabet.rfind(b[i]) + 1
			if a_pos > b_pos:
				a_to_b = 26 - a_pos + b_pos
				b_to_a = a_pos - b_pos
				selection = min(abs(cnt + a_to_b), abs(cnt - b_to_a))
				if selection == abs(cnt + a_to_b):
					cnt += a_to_b
				else:
					cnt -= b_to_a
			elif a_pos < b_pos:
				b_to_a = 26 - b_pos + a_pos
				a_to_b = b_pos - a_pos
				selection = min(abs(cnt + a_to_b), abs(cnt - b_to_a))
				if selection == abs(cnt + a_to_b):
					cnt += a_to_b
				else:
					cnt -= b_to_a
		else:
			cnt = cnt
	print(abs(cnt))
for i in range(int(input())):
	n = int(input())
	a = str(input())
	b = str(input())
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	a_pos = 0
	b_pos = 0
	a_to_b = 0
	b_to_a = 0
	selection = 0
	min_abs_scr(n, a, b)


n = int(input())
while n:
	num = int(input())
	s1 = input()
	s2 = input()
	score = 0
	for i in range(0, num):
		diff12 = 0
		diff21 = 0
		if s1[i] != s2[i]:
			t1 = ord(s1[i])
			t2 = ord(s2[i])
			diff12 = 0
			diff21 = 0
			if t2 > t1:
				diff12 = t2 - t1
				diff21 = 26 - diff12
			elif t1 > t2:
				diff21 = t1 - t2
				diff12 = 26 - diff21
				c = 1
		if abs(score + diff12) < abs(score - diff21):
			score = score + diff12
		else:
			score = score - diff21
	print(abs(score))
	n -= 1


def rshift(a, b):
	if a <= b:
		return ord(b) - ord(a)
	return 26 - ord(a) + ord(b)
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	sc = 0
	for i in range(n):
		sc += rshift(a[i], b[i])
	ans = min(sc % 26, 26 - sc % 26)
	print(ans)


for t in range(int(input())):
	(n, a, b) = (int(input()), input(), input())
	ans = 0
	for i in range(n):
		d = ord(b[i]) - ord(a[i])
		a1 = ans + d if d > 0 else ans + 26 + d
		a2 = ans + d - 26 if d > 0 else ans + d
		ans = a1 if abs(a1) < abs(a2) else a2
	print(abs(ans))


for _ in range(int(input())):
	length = int(input())
	A = input()
	B = input()
	res = 0
	for i in range(length):
		res += ord(A[i]) - ord(B[i]) + 26
	print(min(res % 26, -res % 26))


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = input()
	b = input()
	ans = 0
	for i in range(n):
		ans += ord(b[i]) - ord(a[i])
	ans %= 26
	ans = abs(ans)
	print(min(ans, 26 - ans))


def main():
	T = int(input())
	for counter in range(T):
		diflist = []
		sumdif = 0
		n = int(input())
		a = input()
		b = input()
		for i in range(n):
			if ord(b[i]) == ord(a[i]):
				diflist.append(0)
			elif ord(b[i]) > ord(a[i]):
				diflist.append(ord(b[i]) - ord(a[i]))
				sumdif += ord(b[i]) - ord(a[i])
			else:
				diflist.append(26 - (ord(a[i]) - ord(b[i])))
				sumdif += 26 - (ord(a[i]) - ord(b[i]))
		ans = sumdif
		tempans = ans
		for i in range(n):
			tempans -= 26
			if abs(tempans) < ans:
				ans = abs(tempans)
			else:
				break
		print(ans)
main()


for t in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	(ans, i) = (0, 0)
	while i < n:
		d = ord(b[i]) - ord(a[i])
		if d < 0:
			d += 26
		e = 26 - d
		if abs(ans + d) < abs(ans - e):
			ans += d
		else:
			ans -= e
		i += 1
	print(abs(ans))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	score = 0
	for i in range(n):
		if ord(a[i]) <= ord(b[i]):
			ab = ord(b[i]) - ord(a[i])
		else:
			ab = 26 - (ord(a[i]) - ord(b[i]))
		score += ab
	ans = score % 26
	print(min(ans, 26 - ans))


for i in range(int(input())):
	n = int(input())
	a1 = input()
	b1 = input()
	a = []
	b = []
	for jj in range(n):
		if a1[jj] > b1[jj]:
			a.append(26 - ord(a1[jj]) + ord(b1[jj]))
			b.append(ord(a1[jj]) - ord(b1[jj]))
		else:
			a.append(ord(b1[jj]) - ord(a1[jj]))
			b.append(26 - ord(b1[jj]) + ord(a1[jj]))
	s = 0
	for j in range(n):
		s1 = s + a[j]
		s2 = s - b[j]
		if abs(s1) <= abs(s2):
			s = s1
		else:
			s = s2
	l = []
	r = abs(s) % 26
	print(min(r, 26 - r))


for t in range(int(input())):
	N = int(input())
	(s1, s2) = (input(), input())
	arr = []
	for i in range(N):
		if s2[i] < s1[i]:
			arr.append(ord(s2[i]) - ord(s1[i]) + 26)
		else:
			arr.append(ord(s2[i]) - ord(s1[i]))
	tp = [sum(arr)]
	for i in range(N):
		tp.append(tp[-1] - 26)
	print(min([abs(i) for i in tp]))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	score = 0
	right = []
	left = []
	for i in range(n):
		if a[i] > b[i]:
			difference1 = ord(a[i]) - ord(b[i])
			difference2 = 26 - (ord(a[i]) - ord(b[i]))
			right += [difference2]
			left += [-difference1]
		elif a[i] < b[i]:
			difference1 = ord(b[i]) - ord(a[i])
			difference2 = 26 - (ord(b[i]) - ord(a[i]))
			right += [difference1]
			left += [-difference2]
		else:
			left += [0]
			right += [0]
	score1 = right[0]
	for i in range(1, len(left)):
		if abs(score1 + right[i]) <= abs(score1 + left[i]):
			score1 = score1 + right[i]
		else:
			score1 = score1 + left[i]
	score2 = left[0]
	for i in range(1, len(left)):
		if abs(score2 + right[i]) <= abs(score2 + left[i]):
			score2 = score2 + right[i]
		else:
			score2 = score2 + left[i]
	print(min(abs(score1), abs(score2)))


for i in range(int(input())):
	N = int(input())
	A = input()
	B = input()
	summand = 0
	for i in range(N):
		a_b = 1 * ((ord(B[i]) - ord(A[i])) % 26)
		b_a = -1 * ((ord(A[i]) - ord(B[i])) % 26)
		if abs(summand + a_b) <= abs(summand + b_a):
			summand += a_b
		else:
			summand += b_a
	print(abs(summand))


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	s = 0
	for i in range(n):
		s = s + (ord(s1[i]) - ord(s2[i]))
	s = (s + 26) % 26
	print(min(s, 26 - s))


D = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
T = int(input())
for i in range(T):
	N = int(input())
	A = input()
	B = input()
	a = 0
	for j in range(N):
		x = -1 * (D[A[j]] - D[B[j]])
		if x > 0:
			y = -1 * (26 - abs(x))
		else:
			y = 26 - abs(x)
		c = min(abs(x), abs(y))
		if abs(x) == c:
			a += x
		else:
			a += y
	print(min(a % 26, -a % 26))


for t in range(int(input())):
	n = int(input())
	(a, b) = (input(), input())
	score = 0
	for i in range(n):
		score += ord(b[i]) - ord(a[i])
	score %= 26
	score = (score + 26) % 26
	print(min(abs(score), abs(score - 26)))


for _ in range(int(input())):
	n = int(input())
	(a, b) = (input(), input())
	alphabets = 'abcdefghijklmnopqrstuvwxyz'
	s = 0
	for i in range(n):
		s += (ord(b[i]) - ord(a[i])) % 26
	s = s % 26
	print(min(s, -s % 26))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	s = 0
	for i in range(n):
		va = ord(a[i]) - 97
		vb = ord(b[i]) - 97
		s += vb - va
	s = (s + 26) % 26
	print(min(abs(s), abs(26 - s)))


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	A = []
	for j in range(n):
		if ord(a[j]) > ord(b[j]):
			A.append(26 - ord(a[j]) + ord(b[j]))
		else:
			A.append(ord(b[j]) - ord(a[j]))
	s = sum(A)
	score = s
	for j in range(n + 1):
		if score > abs(s - j * 26):
			score = abs(s - j * 26)
	print(score)


from string import ascii_lowercase
from sys import stdin
alphabet = ascii_lowercase
for _ in range(int(stdin.readline().strip())):
	n = int(stdin.readline().strip())
	a = stdin.readline().strip()
	b = stdin.readline().strip()
	a_scores = []
	b_scores = []
	for i in range(n):
		score = alphabet.index(a[i]) - alphabet.index(b[i])
		if score > 0:
			score -= 26
		score = abs(score)
		a_scores.append(score)
		b_scores.append(abs(26 - score) * -1)
	abs_score = 0
	for x in range(n):
		if abs(abs_score + b_scores[x]) < abs(abs_score + a_scores[x]):
			abs_score += b_scores[x]
		else:
			abs_score += a_scores[x]
	print(abs(abs_score))


a = int(input())
for i in range(a):
	o = c = 0
	b = int(input())
	j = list(map(str, input()))
	h = list(map(str, input()))
	for k in range(b):
		if abs(ord(j[k]) - ord(h[k])) >= 13:
			if j[k] > h[k]:
				c = c + (ord(h[k]) + 26 - ord(j[k]))
			else:
				c = c + (ord(h[k]) - (ord(j[k]) + 26))
		else:
			c = c + (ord(h[k]) - ord(j[k]))
		o = o + c
		c = 0
	print(min(abs(o) % 26, abs(abs(o) % 26 - 26)))
	o = 0


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = inp()
for i in range(t):
	n = inp()
	s1 = st()
	s2 = st()
	l1 = []
	l2 = []
	dp = [None] * (n + 1)
	for i in range(n):
		if s1[i] > s2[i]:
			l1.append(26 - (ord(s1[i]) - ord(s2[i])))
			l2.append(-(ord(s1[i]) - ord(s2[i])))
		else:
			l1.append(ord(s2[i]) - ord(s1[i]))
			l2.append(-(26 - (ord(s2[i]) - ord(s1[i]))))
	s = 0
	for i in range(n):
		if abs(l1[i] + s) < abs(l2[i] + s):
			s += l1[i]
		else:
			s += l2[i]
	print(abs(s))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	arr = []
	for i in range(0, n):
		x = (ord(a[i]) - ord(b[i]) + 26) % 26
		arr.append(x)
	s = sum(arr) % 26
	ans = min(s, 26 - s)
	print(ans)


import numpy as np

def cycle(a, b):
	Alphabet = 'abcdefghijklmnopqrstuvwxyz'
	pos_a = Alphabet.find(a)
	pos_b = Alphabet.find(b)
	if pos_a <= pos_b:
		return pos_b - pos_a
	else:
		return 26 - (pos_a - pos_b)
T = int(input())
for t in range(T):
	N = int(input())
	A = str(input())
	B = str(input())
	Score = 0
	for i in range(N):
		cy = cycle(A[i], B[i])
		Score += cy
	s1 = Score % 26
	s2 = 26 - s1
	print(min(s1, s2))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	sm = 0
	for i in range(n):
		adif = ord(b[i]) - ord(a[i])
		if adif < 0:
			adif = 26 + adif
		if adif == 0:
			bdif = 0
		else:
			bdif = adif - 26
		if abs(sm + adif) < abs(sm + bdif):
			sm += adif
		else:
			sm += bdif
	ans = abs(sm)
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	u = 0
	for j in range(n):
		u += ord(b[j]) - ord(a[j]) + 26
	print(min(u % 26, -u % 26))


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = input()
	b = input()
	arr = []
	for i in range(0, n):
		x = (ord(a[i]) - ord(b[i]) + 26) % 26
		arr.append(x)
	s = sum(arr) % 26
	ans = min(s, 26 - s)
	print(ans)


z = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
for _ in range(int(input())):
	N = int(input())
	A = input().lower()
	B = input().lower()
	score = 0
	for (i, j) in zip(A, B):
		ii = z.index(i)
		jj = z.index(j)
		x = z[ii:].index(j)
		y = z[jj:].index(i)
		if abs(score + x) < abs(score - y):
			score = score + x
		else:
			score = score - y
	print(abs(score))


for _ in range(int(input())):
	n = int(input())
	res = 0
	a = input()
	b = input()
	for i in range(n):
		res += ord(b[i]) - ord(a[i])
	res = res % 26
	res = res + 26 % 26
	print(min(abs(res), abs(26 - res)))


for _ in range(int(input())):
	N = int(input())
	A = input()
	B = input()
	res = 0
	d = {chr(97 + i): i for i in range(26)}
	for i in range(N):
		res += d[B[i]] - d[A[i]]
	res %= 26
	res = (res + 26) % 26
	print(min(abs(res), abs(26 - res)))


for _ in range(int(input())):
	a = int(input())
	x = input()
	y = input()
	n = 0
	for i in range(a):
		n += ord(x[i]) - ord(y[i]) + 26
	print(min(n % 26, -n % 26))


from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

def solve(n, a, b):
	dp = [[None] * 54 for _ in range(n)]
	a = [ord(a[i]) for i in range(n)]
	b = [ord(b[i]) for i in range(n)]

	def go(i, diff):
		if i == n:
			return abs(diff)
		if dp[i][diff + 26] is not None:
			return dp[i][diff + 26]
		inc = 26 - (a[i] - b[i]) if a[i] > b[i] else b[i] - a[i]
		dec = 26 - (b[i] - a[i]) if b[i] > a[i] else a[i] - b[i]
		if a[i] == b[i]:
			dp[i][diff + 26] = go(i + 1, diff)
		elif diff < 0:
			if diff - dec >= -26:
				dp[i][diff + 26] = min(go(i + 1, diff + inc), go(i + 1, diff - dec))
			else:
				dp[i][diff + 26] = go(i + 1, diff + inc)
		elif diff > 0:
			if diff + inc <= 26:
				dp[i][diff + 26] = min(go(i + 1, diff + inc), go(i + 1, diff - dec))
			else:
				dp[i][diff + 26] = go(i + 1, diff - dec)
		else:
			dp[i][diff + 26] = min(go(i + 1, diff + inc), go(i + 1, diff - dec))
		return dp[i][diff + 26]
	return go(0, 0)
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	print(solve(n, a, b))


import sys
f = sys.stdin
next(f)
for (n, a, b) in zip(f, f, f):
	r = sum(((ord(y) - ord(x)) % 26 for (x, y) in zip(a, b))) % 26
	print(r if r < 14 else 26 - r)


for _ in range(int(input())):
	n = int(input())
	(a, b) = (input(), input())
	arr = [[(ord(b[i]) - ord(a[i])) % 26, -((ord(a[i]) - ord(b[i])) % 26)] for i in range(len(a))]
	main = [0, 0]
	for i in range(len(arr)):
		(a, b, c, d) = (arr[i][0] + main[0], arr[i][0] + main[1], arr[i][1] + main[0], arr[i][1] + main[1])
		(pos, neg) = ([a, b, c, d], [a, b, c, d])
		i = 0
		while i < len(pos):
			if pos[i] < 0:
				del pos[i]
			else:
				i += 1
		i = 0
		while i < len(neg):
			if neg[i] > 0:
				del neg[i]
			else:
				i += 1
		if pos:
			main[0] = min(pos)
		else:
			main[0] = float('inf')
		if neg:
			main[1] = max(neg)
		else:
			main[1] = float('-inf')
	print(min(abs(main[0]), abs(main[1])))


import string
t = int(input())
while t > 0:
	n = int(input())
	a = str(input())
	b = str(input())
	ans = 0
	for i in range(0, n):
		if string.ascii_lowercase.index(a[i]) > string.ascii_lowercase.index(b[i]):
			j = 26 - (string.ascii_lowercase.index(a[i]) - string.ascii_lowercase.index(b[i]))
			ans += j
		else:
			k = string.ascii_lowercase.index(b[i]) - string.ascii_lowercase.index(a[i])
			ans += k
	print(min(abs(ans % 26 - 26), ans % 26))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	s = 0
	for i in range(n):
		d1 = ord(s1[i]) - ord(s2[i])
		s += d1
	if s < 0:
		s = (s + 26) % 26
	else:
		s = s % 26
	print(min(s, 26 - s))


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	c = d = 0
	e = f = 0
	for (i, j) in zip(s1, s2):
		c = ord(i) - ord(j)
		d = ord(j) - ord(i)
		if c < 0:
			c += 26
		if d < 0:
			d += 26
		val1 = e + c
		val2 = e - d
		if abs(val1) <= abs(val2):
			f = abs(val1)
			e = val1
		else:
			f = abs(val2)
			e = val2
	print(f)


test = int(input())
while test:
	n = int(input())
	s1 = input()
	s2 = input()
	curr_score = 0
	curr_value = 0
	for (i, j) in zip(s1, s2):
		a_b = ord(j) - ord(i)
		b_a = ord(i) - ord(j)
		if a_b < 0:
			a_b += 26
		if b_a < 0:
			b_a += 26
		val1 = curr_value + a_b
		val2 = curr_value - b_a
		if abs(val1) <= abs(val2):
			curr_score = abs(val1)
			curr_value = val1
		else:
			curr_score = abs(val2)
			curr_value = val2
	print(curr_score)
	test -= 1


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	inc = []
	for i in range(n):
		if ord(b[i]) > ord(a[i]):
			inc.append(abs(ord(b[i]) - ord(a[i])))
		elif ord(a[i]) > ord(b[i]):
			inc.append(26 - (ord(a[i]) - ord(b[i])))
	n = len(inc)
	if n > 0:
		inc.sort()
		insm = [inc[0]]
		for i in range(1, n):
			insm.append(insm[i - 1] + inc[i])
		insm = [0] + insm
		ans = 10000000000.0
		for i in range(n + 1):
			ans = min(ans, abs(insm[n] - insm[i] - (i * 26 - insm[i])))
		print(ans)
	else:
		print(0)


m = {}
for i in range(26):
	m[chr(97 + i)] = i + 1
for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	k1 = []
	k2 = []
	for i in range(n):
		c = abs(m[a[i]] - m[b[i]])
		if m[a[i]] > m[b[i]]:
			k1.append(26 - c)
			k2.append(-1 * c)
		else:
			k2.append(-1 * (26 - c))
			k1.append(c)
	ans = 0
	for i in range(n):
		c1 = k1[i]
		c2 = k2[i]
		d1 = abs(ans + c1)
		d2 = abs(ans + c2)
		if d1 < d2:
			ans += c1
		else:
			ans += c2
	print(abs(ans))