#P1400D. Zigzags

    ID: 5529 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>brute forcecombinatoricsdata structuresmathtwo pointers*1900

Zigzags

No submission language available for this problem.

Description

You are given an array a1,a2ana_1, a_2 \dots a_n. Calculate the number of tuples (i,j,k,l)(i, j, k, l) such that:

  • 1i<j<k<ln1 \le i < j < k < l \le n;
  • ai=aka_i = a_k and aj=ala_j = a_l;

The first line contains a single integer tt (1t1001 \le t \le 100) — the number of test cases.

The first line of each test case contains a single integer nn (4n30004 \le n \le 3000) — the size of the array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ain1 \le a_i \le n) — the array aa.

It's guaranteed that the sum of nn in one test doesn't exceed 30003000.

For each test case, print the number of described tuples.

Input

The first line contains a single integer tt (1t1001 \le t \le 100) — the number of test cases.

The first line of each test case contains a single integer nn (4n30004 \le n \le 3000) — the size of the array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ain1 \le a_i \le n) — the array aa.

It's guaranteed that the sum of nn in one test doesn't exceed 30003000.

Output

For each test case, print the number of described tuples.

Samples

Sample Input 1

2
5
2 2 2 2 2
6
1 3 3 1 2 3

Sample Output 1

5
2

Note

In the first test case, for any four indices i<j<k<li < j < k < l are valid, so the answer is the number of tuples.

In the second test case, there are 22 valid tuples:

  • (1,2,4,6)(1, 2, 4, 6): a1=a4a_1 = a_4 and a2=a6a_2 = a_6;
  • (1,3,4,6)(1, 3, 4, 6): a1=a4a_1 = a_4 and a3=a6a_3 = a_6.