To make Yalalovichik even more satisfied and happy, Jafar decided to invent Yalalovichik strings. A string is called a Yalalovichik string if the set of all of its distinct non-empty substrings is equal to the set of all of its distinct non-empty subsequences. 
You are given a string S$S$. You need to find the number of its distinct non-empty substrings which are Yalalovichik strings.
Note: A string A$A$ is called a subsequence of a string B$B$ if A$A$ can be formed by erasing some characters (possibly none) from B$B$. A string A$A$ is called a substring of a string B$B$ if it can be formed by erasing some characters (possibly none) from the beginning of B$B$ and some (possibly none) from the end of B$B$. Two substrings or subsequences are considered different if they are different strings.

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of each test case contains a single integer N=|S|$N = |S|$.
- The second line contains the string S$S$.

-----Output-----
For each test case, print a single line containing one integer — the number of distinct Yalalovichik substrings of S$S$.

-----Constraints-----
- 1≤T≤100$1 \le T \le 100$
- 1≤N≤106$1 \le N \le 10^6$
- the sum of N$N$ over all test cases does not exceed 2⋅106$2 \cdot 10^6$
- S$S$ contains only lowercase English letters

-----Example Input-----
1
3
xxx

-----Example Output-----
3

-----Explanation-----
Example case 1: The distinct Yalalovichik substrings are "x", "xx" and "xxx".

Source: codechef | Difficulty: VERY_HARD


Solutions:
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input().strip()
	previ = s[0]
	num = 0
	_s = []
	dic = {}
	for i in s:
		if previ == i:
			num += 1
			continue
		_s.append((previ, num))
		if previ not in dic or dic[previ] < num:
			dic[previ] = num
		previ = i
		num = 1
	_s.append((previ, num))
	if previ not in dic or dic[previ] < num:
		dic[previ] = num
	sum1 = sum(dic.values())
	del dic, s
	l = [i for (i, j) in _s]
	congr = [(l[i], l[i + 1]) for i in range(len(l) - 1)]
	dicc = {}
	for i in range(len(congr)):
		if congr[i] not in dicc:
			dicc[congr[i]] = set()
		dicc[congr[i]].add((_s[i][1], _s[i + 1][1]))
	sum2 = 0
	ll = []
	for i in dicc.keys():
		theset = dicc[i]
		sortedset = sorted(list(theset))
		deleted = []
		for k in range(1, len(sortedset)):
			j = sortedset[k]
			if j[1] > sortedset[k - 1][1]:
				ind = k - 1
				while ind >= 0 and j[1] >= sortedset[ind][1]:
					deleted.append(ind)
					ind = ind - 1
			elif j[1] == sortedset[k - 1][1]:
				deleted.append(k - 1)
			elif j[0] == sortedset[k - 1][0] and j[1] < sortedset[k - 1][1]:
				deleted.append(k)
		dicc[i] = sorted(list(set(sortedset) - {sortedset[i] for i in deleted}), key=lambda x: x[0])
		prevx = 0
		thissum = 0
		for j in dicc[i]:
			(x, y) = j
			thissum += (x - prevx) * y
			prevx = x
		sum2 += thissum
		ll.append((i, thissum))
	ll.sort(key=lambda x: x[0])
	thesum = sum1 + sum2
	print(thesum)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input().strip()
	previ = s[0]
	num = 0
	_s = []
	dic = {}
	for i in s:
		if previ == i:
			num += 1
			continue
		_s.append((previ, num))
		if previ not in dic or dic[previ] < num:
			dic[previ] = num
		previ = i
		num = 1
	_s.append((previ, num))
	if previ not in dic or dic[previ] < num:
		dic[previ] = num
	sum1 = sum(dic.values())
	del dic, s


for _ in range(int(input())):
	(n, s) = (int(input()), input().strip())
	(previ, num, _s, dic) = (s[0], 0, [], {})
	for i in s:
		if previ == i:
			num += 1
			continue
		_s.append((previ, num))
		if previ not in dic or dic[previ] < num:
			dic[previ] = num
		(previ, num) = (i, 1)
	_s.append((previ, num))
	if previ not in dic or dic[previ] < num:
		dic[previ] = num
	sum1 = sum(dic.values())
	del dic, s
	(l, dicc) = ([i for (i, j) in _s], {})
	congr = [(l[i], l[i + 1]) for i in range(len(l) - 1)]
	for i in range(len(congr)):
		if congr[i] not in dicc:
			dicc[congr[i]] = set()
		dicc[congr[i]].add((_s[i][1], _s[i + 1][1]))
	(sum2, ll) = (0, [])
	for i in dicc.keys():
		(sortedset, deleted) = (sorted(list(dicc[i])), [])
		for k in range(1, len(sortedset)):
			j = sortedset[k]
			if j[1] > sortedset[k - 1][1]:
				ind = k - 1