Balanced Pairs - Beta
Submissions: 0   Accuracy:

0%

  Max. Score:

50

Given an array of positive integers. Find the number of ordered pairs (i, j) such that A[i] = A[j] and there does not exist any element between i and j whose value is greater than A[i].

Input

First line of input contains number of testcases T. For each testcase T, first line contains the number of elements N in the array and the second line contains N space separated integers.

Output

For each test, output the required number of pairs.
Constraints

1 ≤ T ≤ 10

1 ≤ N ≤ 105

1 ≤ Ai ≤ 103

Sample Input

1
6

4 3 1 3 4 4

Sample Output

8


to report an issue on this page.