#P1974C. Beautiful Triple Pairs

    ID: 9296 Type: RemoteJudge 4000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>combinatoricsdata structures*1400

Beautiful Triple Pairs

No submission language available for this problem.

Description

Polycarp was given an array aa of nn integers. He really likes triples of numbers, so for each jj (1jn21 \le j \le n - 2) he wrote down a triple of elements [aj,aj+1,aj+2][a_j, a_{j + 1}, a_{j + 2}].

Polycarp considers a pair of triples bb and cc beautiful if they differ in exactly one position, that is, one of the following conditions is satisfied:

  • b1c1b_1 \ne c_1 and b2=c2b_2 = c_2 and b3=c3b_3 = c_3;
  • b1=c1b_1 = c_1 and b2c2b_2 \ne c_2 and b3=c3b_3 = c_3;
  • b1=c1b_1 = c_1 and b2=c2b_2 = c_2 and b3c3b_3 \ne c_3.

Find the number of beautiful pairs of triples among the written triples [aj,aj+1,aj+2][a_j, a_{j + 1}, a_{j + 2}].

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (3n21053 \le n \le 2 \cdot 10^5) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1061 \le a_i \le 10^6) — the elements of the array.

It is guaranteed that the sum of the values of nn for all test cases in the test does not exceed 21052 \cdot 10^5.

For each test case, output a single integer — the number of beautiful pairs of triples among the pairs of the form [aj,aj+1,aj+2][a_j, a_{j + 1}, a_{j + 2}].

Note that the answer may not fit into 32-bit data types.

Input

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (3n21053 \le n \le 2 \cdot 10^5) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1061 \le a_i \le 10^6) — the elements of the array.

It is guaranteed that the sum of the values of nn for all test cases in the test does not exceed 21052 \cdot 10^5.

Output

For each test case, output a single integer — the number of beautiful pairs of triples among the pairs of the form [aj,aj+1,aj+2][a_j, a_{j + 1}, a_{j + 2}].

Note that the answer may not fit into 32-bit data types.

Sample Input 1

8
5
3 2 2 2 3
5
1 2 1 2 1
8
1 2 3 2 2 3 4 2
4
2 1 1 1
8
2 1 1 2 1 1 1 1
7
2 1 1 1 1 1 1
6
2 1 1 1 1 1
5
2 1 1 1 1

Sample Output 1

2
0
3
1
8
4
3
2

Note

In the first example, a=[3,2,2,2,3]a = [3, 2, 2, 2, 3], Polycarp will write the following triples:

  1. [3,2,2][3, 2, 2];
  2. [2,2,2][2, 2, 2];
  3. [2,2,3][2, 2, 3].
The beautiful pairs are triple 11 with triple 22 and triple 22 with triple 33.

In the third example, a=[1,2,3,2,2,3,4,2]a = [1, 2, 3, 2, 2, 3, 4, 2], Polycarp will write the following triples:

  1. [1,2,3][1, 2, 3];
  2. [2,3,2][2, 3, 2];
  3. [3,2,2][3, 2, 2];
  4. [2,2,3][2, 2, 3];
  5. [2,3,4][2, 3, 4];
  6. [3,4,2][3, 4, 2];
The beautiful pairs are triple 11 with triple 44, triple 22 with triple 55, and triple 33 with triple 66.