All submissions for this problem are available.

Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.

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 ≤ ab < cdN) 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

  • 1T5
  • 1N1000
  • 1Ai109

Subtasks

Subtask 1 (7 points)

  • 1N20

Subtask 2 (34 points)

  • 1N300

Subtask 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]}.


Author: antoniuk1
Tester: mugurelionut
Editorial: http://discuss.codechef.com/problems/CHSGMNTS
Tags: antoniuk1 dp july16 medium
Date Added: 18-07-2015
Time Limit: 1 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.4, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC