Chef has two strings A and B consisting of lowercase alphabets, each of length N. Help Chef in finding the number of indices i (1 ≤ i ≤ N) such that A[i \dots N] < B[i \dots N].

S[i \dots N] denotes the suffix of string S starting at index i, i.e. S_{iS}_{i+1} \dots S_{N}. 
String S < String T denotes that S is lexicographically smaller than T. If two strings S and T have the same length N, we say that S is lexicographically smaller than T if there exists an index i(1 ≤ i ≤ N) such that S_{1} = T_{1}, S_{2} = T_{2}, \ldots, S_{i-1} = T_{i-1} and S_{i} < T_{i}. For example, "abc" is lexicographically smaller than "acd", "abe", but not smaller than "abc", "aac".

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

- The first line contains T denoting the number of test cases. Then the test cases follow.
- The first line of each test case contains N, denoting the length of the strings A and B.
- The second line of each test case contains the string A.
- The third line of each test case contains the string B.

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

For each test case, print a single line containing one integer -  the number of indices i such that A[i \dots N] < B[i\dots N].

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

$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{6}$
- The sum of $N$ over all test cases does not exceed $10^{6}$

----- Sample Input 1 ------ 
2
2
ab
bb
3
aaa
aab
----- Sample Output 1 ------ 
1
3

----- explanation 1 ------ 
Test Case $1$: 
- For $i = 1$, $A[1 \dots 2] = $ "$ab$", $B[1 \dots 2] = $ "$bb$" and lexicographically, "$ab$" $<$ "$bb$".
- For $i = 2$, $A[2 \dots 2] =$ "$b$", $B[2 \dots 2] = $ "$b$" and lexicographically, "$b$" $=$ "$b$".

Test Case $2$: For each $i \in \{1 , 2, 3\}$, $A[i \dots 3] < B[i \dots 3]$.

Difficulty: MEDIUM_HARD

Solutions:
for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	c = 0
	d = 0
	for i in range(n):
		if ord(a[i]) < ord(b[i]):
			c += i + 1 - d
			d = i + 1
		elif ord(a[i]) > ord(b[i]):
			d = i + 1
		else:
			continue
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = input()
	p = input()
	c = 1 if p[-1] > s[-1] else 0
	flag = True if p[-1] > s[-1] else False
	for i in range(n - 2, -1, -1):
		if s[i] < p[i]:
			flag = True
			c += 1
		elif s[i] > p[i]:
			flag = False
		elif flag:
			c += 1
	print(c)


t = int(input())
while t > 0:
	n = int(input())
	s1 = input()
	s2 = input()
	cnt = 0
	flag = False
	for i in reversed(range(n)):
		if s1[i] < s2[i]:
			flag = True
			cnt += 1
		elif s1[i] > s2[i]:
			flag = False
		elif flag:
			cnt += 1
	print(cnt)
	t -= 1


import sys
from collections import Counter, deque
from math import gcd, sqrt, ceil

def li():
	return [int(i) for i in sys.stdin.readline().split()]

def si():
	return sys.stdin.readline().split()

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

def ip():
	return input()
for tastcas in range(int(input())):
	n = ii()
	a = ip()
	b = ip()
	c = 0
	f = a[n - 1] < b[n - 1]
	if f:
		c += 1
	for i in range(n - 2, -1, -1):
		if a[i] < b[i]:
			c += 1
			f = 1
		elif a[i] > b[i]:
			f = 0
		elif f:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	ans = 0
	f = b[n - 1] > a[n - 1]
	if f:
		ans += 1
	for j in range(n - 2, -1, -1):
		if b[j] > a[j]:
			f = True
			ans += 1
		elif b[j] < a[j]:
			f = False
		elif f:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	ans = 0
	flag = b[n - 1] > a[n - 1]
	if flag:
		ans += 1
	for i in range(n - 2, -1, -1):
		if b[i] > a[i]:
			flag = True
			ans += 1
		elif b[i] < a[i]:
			flag = False
		elif flag:
			ans += 1
	print(ans)


for _ in range(int(input())):
	x = int(input())
	a = str(input())
	b = str(input())
	ans = 0
	flag = False
	for i in range(x - 1, -1, -1):
		if a[i] < b[i]:
			ans += 1
			flag = True
		elif a[i] > b[i]:
			flag = False
		elif a[i] == b[i]:
			if flag:
				ans += 1
			continue
	print(ans)


n = int(input())
for i in range(n):
	k = int(input())
	st1 = input()
	st2 = input()
	x = 0
	y = 0
	z = 0
	l = []
	for i in range(k):
		if st1[i] == st2[i]:
			x += 1
		elif st1[i] < st2[i]:
			y += 1
			z += x
			x = 0
		else:
			x = 0
	print(z + y)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = input()
		b = input()
		same = 0
		counter = 0
		for i in range(n):
			if a[i] < b[i]:
				counter += 1 + same
				same = 0
			elif a[i] == b[i]:
				same += 1
			else:
				same = 0
		print(counter)
main()


def main():
	for _ in range(int(input())):
		n = int(input())
		e = input()
		k = input()
		same = 0
		counter = 0
		for i in range(n):
			if e[i] < k[i]:
				counter += 1 + same
				same = 0
			elif e[i] == k[i]:
				same += 1
			else:
				same = 0
		print(counter)
main()


import math
for i in range(int(input())):
	n = int(input())
	A = input()
	B = input()
	l = 0
	o = 0
	for k in range(n - 1, -1, -1):
		if A[k] == B[k] and o != 0:
			l = l + 1
		elif A[k] < B[k]:
			o = 1
			l += 1
		else:
			o = 0
	print(l)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	count = 0
	up = False
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			count += 1
			up = True
		elif a[i] == b[i] and up:
			count += 1
		else:
			up = False
	print(count)


def compstr(S1, S2, n) -> int:
	indx = 0
	tag = False
	for a in range(n - 1, -1, -1):
		if S1[a] < S2[a]:
			indx += 1
			tag = True
		elif S1[a] == S2[a] and tag == True:
			indx += 1
		else:
			tag = False
	return indx
t = int(input())
while t > 0:
	print(compstr(n=int(input()), S1=input(), S2=input()))
	t -= 1


def compstr(A, B, n) -> int:
	indices = 0
	flag = False
	for a in range(n - 1, -1, -1):
		if A[a] < B[a]:
			indices += 1
			flag = True
		elif A[a] == B[a] and flag == True:
			indices += 1
		else:
			flag = False
	return indices
t = int(input())
while t > 0:
	print(compstr(n=int(input()), A=input(), B=input()))
	t -= 1


for _______ in range(int(input())):
	_ = int(input())
	__ = input()
	___ = input()
	____ = 0
	_____ = 0
	for ______ in range(len(__) - 1, -1, -1):
		if __[______] < ___[______]:
			_____ = 1
			____ += 1
		elif __[______] == ___[______]:
			if _____ == 1:
				____ += 1
		else:
			_____ = 0
	print(____)


for i in range(int(input())):
	n = int(input())
	a = str(input())
	b = str(input())
	c = 0
	ans = 0
	for j in range(n - 1, -1, -1):
		if a[j] < b[j]:
			ans += 1
			c = 1
		elif a[j] == b[j]:
			if c == 1:
				ans += 1
		else:
			c = 0
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	ind = eq = 0
	for i in range(n):
		if a[i] < b[i]:
			ind += eq + 1
			eq = 0
		elif a[i] == b[i]:
			eq += 1
		else:
			eq = 0
	print(ind)


try:
	t = int(input())
	for i in range(0, t, 1):
		n = int(input())
		a = input()
		b = input()
		f = False
		ans = 0
		for j in range(n - 1, -1, -1):
			if a[j] < b[j]:
				f = True
				ans += 1
			elif a[j] > b[j]:
				f = False
			elif a[j] == b[j]:
				if f:
					ans = ans + 1
				continue
		print(ans)
except:
	pass


t = int(input())
while t > 0:
	l = int(input())
	str1 = str(input())
	str2 = str(input())
	maxdif = 0
	flag = False
	for i in range(l - 1, -1, -1):
		if str1[i] < str2[i]:
			maxdif += 1
			flag = True
		elif str1[i] > str2[i]:
			flag = False
		elif str1[i] == str2[i]:
			if flag:
				maxdif += 1
			continue
	print(maxdif)
	t = t - 1


import math, os, io, heapq
from sys import stdin, stdout
from collections import Counter, deque, defaultdict
from itertools import product
import bisect

def getList(method=int):
	return list(map(method, input().split()))

def getInt():
	return int(input())

def solve():
	n = getInt()
	(a, b) = (input(), input())
	(ans, nxt) = (0, False)
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			ans += 1
			nxt = True
		elif a[i] == b[i]:
			if nxt:
				ans += 1
		else:
			nxt = False
	print(ans)
for _ in range(getInt()):
	solve()


for i in range(int(input())):
	n = int(input())
	A = input()
	B = input()
	s = 0
	l = 0
	if A == B:
		print(s)
	else:
		for k in range(n):
			if A[k] < B[k]:
				s += l + 1
				l = 0
			elif A[k] > B[k]:
				l = 0
			else:
				l += 1
		print(s)


def solve(a, b, n):
	ind = n - 1
	memo = [0] * n
	while ind >= 0:
		if a[ind] < b[ind]:
			memo[ind] = 1
		elif a[ind] > b[ind]:
			memo[ind] = 0
		elif ind == n - 1:
			memo[ind] = 0
		else:
			memo[ind] = memo[ind + 1]
		ind -= 1
	return sum(memo)
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	print(solve(a, b, n))


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	count = 0
	prev = 'E'
	for i in range(n - 1, -1, -1):
		if a[i] == b[i]:
			if prev == 's':
				count += 1
		elif a[i] < b[i]:
			prev = 's'
			count += 1
		else:
			prev = 'g'
	print(count)


try:
	for _ in range(int(input())):
		n = int(input())
		a = input()
		b = input()
		ans = 0
		i = 0
		while i < n:
			flag = 0
			for j in range(i, n):
				if a[j] < b[j]:
					ans += j - i + 1
					i = j
					break
				elif a[j] > b[j]:
					i = j
					break
				if j == n - 1:
					flag = 1
					break
			if flag:
				break
			i += 1
		print(ans)
except:
	pass


n = int(input())
for i in range(n):
	n = int(input())
	s1 = input()
	s2 = input()
	e = 0
	count = 0
	ans = 0
	l = []
	for i in range(n):
		if s1[i] == s2[i]:
			e = e + 1
		elif s1[i] < s2[i]:
			count += 1
			ans += e
			e = 0
		else:
			e = 0
	print(ans + count)


for t in range(int(input())):
	n = int(input())
	a = input().strip()
	b = input().strip()
	ans = 0
	t = 0
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			ans += 1
			t = 1
		elif a[i] > b[i]:
			t = 0
		elif t:
			ans += 1
			continue
	print(ans)


import sys, io, os
for test in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ans = 0
	t = 0
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			ans += 1
			t = 1
		elif a[i] > b[i]:
			t = 0
		elif t:
			ans += 1
			continue
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	c = i = ans = 0
	while i < n:
		if a[i] == b[i]:
			c += 1
		elif a[i] > b[i]:
			c = 0
		else:
			ans += c + 1
			c = 0
		i += 1
	print(ans)


import sys
input = sys.stdin.readline
num_test_cases = int(input())
for _ in range(num_test_cases):
	n = int(input())
	a = input()
	b = input()
	ans = 0
	who_was_bigger_before = None
	for i in range(n - 1, -1, -1):
		letter_a = a[i]
		letter_b = b[i]
		if letter_a < letter_b:
			ans += 1
			who_was_bigger_before = 'b'
		elif letter_a == letter_b:
			if who_was_bigger_before == 'b':
				ans += 1
		else:
			who_was_bigger_before = 'a'
	print(ans)


def solve():
	n = int(input())
	a = input()
	b = input()
	x = 0
	ans = 0
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			ans += 1
			x = 1
		elif a[i] > b[i]:
			x = 0
		elif x == 1:
			ans += 1
	print(ans)
for iii in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	a = int(input())
	x = str(input())
	y = str(input())
	count = 0
	f = False
	for i in range(a - 1, -1, -1):
		if x[i] < y[i]:
			count += 1
			f = True
		elif x[i] > y[i]:
			f = False
		elif x[i] == y[i]:
			if f == True:
				count += 1
			continue
	print(count)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list((i for i in input()))
	b = list((i for i in input()))
	c = 0
	prev = 0
	for i in range(n):
		if a[n - 1 - i] < b[n - 1 - i]:
			c += 1
			prev = 1
		elif a[n - 1 - i] > b[n - i - 1]:
			prev = -1
		elif prev == 1:
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	A = input()
	B = input()
	ans = 0
	i = 0
	while i < n:
		j = i
		over = False
		while j < n:
			if A[j] < B[j]:
				ans += j - i + 1
				i = j
				break
			elif A[j] > B[j]:
				i = j
				break
			if j == n - 1:
				over = True
			j += 1
		if over:
			break
		i += 1
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	A = [x for x in input()]
	B = [x for x in input()]
	ans = 0
	temp = 0
	for i in range(n):
		a = A[n - i - 1]
		b = B[n - i - 1]
		if a < b:
			ans += 1
			temp = 1
		elif a == b and temp == 1:
			ans += 1
			temp = 1
		else:
			temp = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	c = 0
	f = False
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			c += 1
			f = True
		elif a[i] > b[i]:
			f = False
		elif a[i] == b[i]:
			if f:
				c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	(ans, f) = (0, 0)
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			ans += 1
			f = 1
		elif a[i] > b[i]:
			f = 0
		elif a[i] == b[i]:
			if f:
				ans += 1
				continue
	print(ans)


for i in range(int(input())):
	x = int(input())
	s1 = input()
	s2 = input()
	s = 0
	c = 0
	p = 1
	if s1 == s2:
		print('0')
		continue
	for j in range(x):
		if s1[j] < s2[j]:
			s = s + c + 1
			c = 0
		elif s1[j] > s2[j]:
			c = 0
			p = p + 1
		else:
			c = c + 1
	print(s)


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	flag = False
	count = 0
	for j in range(n - 1, -1, -1):
		if a[j] < b[j]:
			count += 1
			flag = True
		elif a[j] > b[j]:
			flag = False
		elif a[j] == b[j]:
			if flag:
				count += 1
			continue
	print(count)


for i in range(int(input())):
	x = int(input())
	a = str(input())
	b = str(input())
	count = 0
	f = 0
	f1 = 0
	flag = False
	for i in range(x - 1, -1, -1):
		if a[i] < b[i]:
			count += 1
			flag = True
		elif a[i] > b[i]:
			flag = False
		elif a[i] == b[i]:
			if flag:
				count += 1
			continue
	print(count)


for _ in range(int(input())):
	n = int(input())
	str1 = input()
	str2 = input()
	ans = 0
	i = 0
	j = 0
	while j < n:
		if str1[j] == str2[j]:
			j += 1
		elif str1[j] < str2[j]:
			ans += j - i + 1
			j += 1
			i = j
		else:
			j += 1
			i = j
	print(ans)


def function1(n, str1, str2):
	(i, j, count) = (0, 0, 0)
	for i in range(len(str1)):
		if ord(str1[i]) < ord(str2[i]):
			count += 1
			count += j
			j = 0
		elif ord(str1[i]) == ord(str2[i]):
			j += 1
		else:
			j = 0
	return count
t = int(input())
while t > 0:
	n = int(input())
	str1 = input()
	str2 = input()
	print(function1(n, str1, str2))
	t -= 1


import sys

def solve(N, A, B):
	(count, temp) = (0, 0)
	for i in range(N):
		if A[i] < B[i]:
			if temp > 0:
				count += temp
				temp = 0
			count += 1
		elif A[i] == B[i]:
			temp += 1
		elif A[i] > B[i]:
			temp = 0
	return count

def main():
	test_case = int(sys.stdin.readline())
	for tc in range(test_case):
		N = int(sys.stdin.readline())
		A = sys.stdin.readline()
		B = sys.stdin.readline()
		print(solve(N, A, B))
main()


t = int(input())
for zz in range(t):
	n = int(input())
	a = input()
	b = input()
	(c, z) = (0, 1)
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			z = 0
		elif a[i] > b[i]:
			z = 1
		if z == 0:
			c += 1
	print(c)


T = int(input())
V = []
while T > 0:
	v = 0
	N = int(input())
	A = input()
	B = input()
	y = 0
	for i in range(N):
		if A[i] < B[i]:
			v = v + 1
			if y != 0:
				v = v + y
				y = 0
		elif A[i] == B[i]:
			y = y + 1
		elif A[i] > B[i]:
			y = 0
	V.append(v)
	T = T - 1
for i in V:
	print(i)


for t in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	flag = False
	count = 0
	i = 0
	while i < n:
		for j in range(i, n):
			if a[j] < b[j]:
				count += j - i + 1
				i = j
				break
			elif a[j] > b[j]:
				i = j
				break
			if j == n - 1:
				flag = True
		if flag:
			break
		i += 1
	print(count)


ans = ''
for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	count = 0
	is_s_small = -1
	for i in range(len(s) - 1, -1, -1):
		if s[i] < t[i]:
			count += 1
			is_s_small = 1
		elif s[i] > t[i]:
			is_s_small = 0
		elif is_s_small == 1:
			count += 1
	ans += str(count) + '\n'
print(ans)


t = int(input())
for val in range(0, t):
	n = int(input())
	a = str(input())
	b = str(input())
	ans = 0
	flag = False
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			ans += 1
			flag = True
		elif a[i] > b[i]:
			flag = False
		elif a[i] == b[i]:
			if flag:
				ans += 1
			continue
	print(ans)


try:
	t = int(input())
	while t >= 0:
		t -= 1
		n = int(input())
		a = list(input())
		b = list(input())
		c = 0
		k = 0
		for i in range(n - 1, -1, -1):
			if a[i] < b[i]:
				c += 1
				k = 1
			if a[i] == b[i] and k == 1:
				c += 1
			if a[i] > b[i]:
				k = 0
		print(c)
except:
	pass


for _ in '.' * int(input()):
	n = int(input())
	(s, t) = (input(), input())
	ans = 0
	l = False
	for i in range(n - 1, -1, -1):
		if s[i] < t[i]:
			l = True
		elif s[i] > t[i]:
			l = False
		ans += l
	print(ans)


a = int(input())
for i in range(a):
	l = int(input())
	s1 = input()
	s2 = input()
	c = 0
	flag = False
	for i in range(l - 1, -1, -1):
		if s1[i] < s2[i]:
			flag = True
			c += 1
		elif s1[i] > s2[i]:
			flag = False
		elif s1[i] == s2[i]:
			if flag:
				c += 1
			continue
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	q = input()
	c = 0
	w = 0
	i = n - 1
	while i >= 0:
		if s[i] < q[i]:
			w = 1
			c = c + 1
		elif s[i] == q[i] and w == 1:
			c = c + 1
		elif w == 1 and s[i] > q[i]:
			w = 0
		i = i - 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	c = 0
	flag = False
	for i in range(n - 1, -1, -1):
		if s1[i] > s2[i]:
			flag = False
			continue
		elif s1[i] < s2[i]:
			c += 1
			flag = True
		elif s1[i] == s2[i]:
			if flag == True:
				c += 1
			else:
				continue
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	c = 0
	flag = 0
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			c += 1
			flag = 1
		elif a[i] == b[i] and flag == 1:
			c += 1
		elif flag == 1 and a[i] > b[i]:
			flag = 0
	print(c)


for i in range(int(input())):
	n = int(input())
	a = input()[:n]
	b = input()[:n]
	flag = 0
	count = 0
	if a[n - 1] < b[n - 1]:
		flag = 1
		count += 1
	for i in range(n - 2, -1, -1):
		if a[i] < b[i]:
			flag = 1
			count += 1
		elif a[i] == b[i]:
			if flag == 1:
				count += 1
		else:
			flag = 0
	print(count)


t = int(input())
for x in range(t):
	n = int(input())
	a = input()
	b = input()
	count = 0
	fin = 0
	for i in range(n):
		if a[i] == b[i]:
			count += 1
		elif a[i] < b[i]:
			fin += count + 1
			count = 0
		elif a[i] > b[i]:
			count = 0
	print(fin)


for _ in range(int(input())):
	n = int(input())
	c = 0
	k = 0
	a = input()
	b = input()
	for i in range(n):
		if ord(a[i]) > ord(b[i]):
			k = 0
		elif ord(a[i]) == ord(b[i]):
			k += 1
		else:
			c += 1
			c += k
			k = 0
	print(c)


n = int(input())
for i in range(1, n + 1):
	c = int(input())
	s1 = input()
	s2 = input()
	c1 = 0
	f = False
	for j in range(c - 1, -1, -1):
		if s1[j] < s2[j]:
			c1 += 1
			f = True
		elif s1[j] == s2[j]:
			if f:
				c1 += 1
				continue
		elif s1[j] > s2[j]:
			f = False
	print(c1)


for _ in range(int(input())):
	x = int(input())
	a = input()
	b = input()
	cnt = 0
	flag = False
	for i in range(x - 1, -1, -1):
		if a[i] < b[i]:
			cnt += 1
			flag = True
		elif a[i] > b[i]:
			flag = False
		elif a[i] == b[i]:
			if flag:
				cnt += 1
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	flag = 0
	ans = 0
	for i in range(n - 1, -1, -1):
		if a[i] < b[i]:
			flag = 1
			ans += 1
		elif a[i] > b[i]:
			flag = 0
		elif flag == 1:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	isSmaller = [None] * (n + 1)
	(s, t) = (input(), input())
	for i in range(n - 1, -1, -1):
		if s[i] < t[i]:
			isSmaller[i] = True
		elif s[i] > t[i]:
			isSmaller[i] = False
		else:
			isSmaller[i] = isSmaller[i + 1]
	print(isSmaller.count(True))