Chef has an array A consisting of N elements. He wants to find number of pairs of non-intersecting segments [a, b] and [c, d] (1 ≤ a ≤ b < c ≤ d ≤ N) such there is no number that occurs in the subarray {Aa, Aa+1, ... , Ab} and   {Ac, Ac+1, ... , Ad} simultaneously. 
Help Chef to find this number.

-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N denoting the number of elements in the array.
- The second line contains N space-separated integers A1, A2, ..., AN. 

-----Output-----
- For each test case, output a single line containing one integer - number of pairs of non-intersecting segments. 

-----Constraints-----
- 1 ≤ T ≤ 5
- 1 ≤ N ≤ 1000
- 1 ≤ Ai ≤ 109

-----Subtasks-----Subtask 1 (7 points)
- 1 ≤ N ≤ 20Subtask 2 (34 points)
- 1 ≤ N ≤ 300Subtask 3 (59 points)
- Original constraints

-----Example-----
Input:
2
3
1 2 3
4
1 2 1 2

Output:
5
4

-----Explanation-----
Example case 1.
All possible variants are correct: {[1, 1], [2, 2]}, {[1, 1], [2, 3]}, {[1, 2], [3, 3]}, {[2, 2], [3, 3]}, {[1,1], [3, 3]}.

Example case 2.
Correct segments: {[1, 1], [2, 2]}, {[1, 1], [4, 4]}, {[2, 2], [3, 3]}, {[3, 3], [4, 4]}.

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
def repeats(A, x):
	for i in range(N):
		if x == A[i]:
			return i
	return -1

def assign_indices(A, newA):
	for i in range(N):
		x = repeats(A, A[i])
		if x == -1:
			newA[i] = i
		else:
			newA[i] = x
T = int(input())
for t in range(T):
	N = int(input())
	A = input().split(' ')
	indices = [0 for x in range(1005)]
	for i in range(N):
		A[i] = int(A[i])
	assign_indices(A, indices)
	total = 0
	taken = []
	for i in range(N - 1):
		taken = [0 for x in range(1005)]
		for j in range(i, N):
			before = 0
			taken[indices[j]] += 1
			for k in range(j + 1, N):
				if taken[indices[k]] == 0:
					total = total + (k - j) - before
				else:
					before = k - j
	print(total)


t = int(input())
for q in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	dic = {}
	counter = 0
	for i in range(n - 1):
		if x[i] in dic:
			dic[x[i]] += 1
		else:
			dic[x[i]] = 1
		for j in range(i, n - 1):
			if x[j] in dic:
				dic[x[j]] += 1
			else:
				dic[x[j]] = 1
			for p in range(j + 1, n):
				if x[p] in dic:
					continue
				for q in range(p, n):
					if x[q] in dic:
						break
					counter += 1
		dic.clear()
	print(counter)


for _ in range(eval(input())):
	n = eval(input())
	l = list(map(int, input().split()))
	c = 0
	s = []
	for i in range(n):
		for j in range(i, n):
			s += [set(l[i:j + 1])]
	for i in range(len(s)):
		for j in range(i + 1, len(s)):
			c += len(s[i] & s[j]) == 0
	print(c)


t = eval(input())
while t > 0:
	n = eval(input())
	ar = list(map(int, input().split()))
	c = 0
	for i in range(0, n):
		for j in range(i, n):
			for k in range(j + 1, n):
				for l in range(k, n):
					res = []
					res = list(set(ar[i:j + 1]).intersection(set(ar[k:l + 1])))
					if len(res) == 0:
						c += 1
	print(c)
	t -= 1