---
{"category_name":"easy","problem_code":"WEIRD2","problem_name":"Weird Question","languages_supported":{"0":"C","1":"CPP14","2":"JAVA","3":"PYTH","4":"PYTH 3.6","5":"PYPY","6":"CS2","7":"PAS fpc","8":"PAS gpc","9":"RUBY","10":"PHP","11":"GO","12":"NODEJS","13":"HASK","14":"rust","15":"SCALA","16":"swift","17":"D","18":"PERL","19":"FORT","20":"WSPC","21":"ADA","22":"CAML","23":"ICK","24":"BF","25":"ASM","26":"CLPS","27":"PRLG","28":"ICON","29":"SCM qobi","30":"PIKE","31":"ST","32":"NICE","33":"LUA","34":"BASH","35":"NEM","36":"LISP sbcl","37":"LISP clisp","38":"SCM guile","39":"JS","40":"ERL","41":"TCL","42":"kotlin","43":"PERL6","44":"TEXT","45":"SCM chicken","46":"PYP3","47":"CLOJ","48":"COB","49":"FS"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"kingofnumbers","problem_tester":null,"date_added":"26-10-2018","tags":{"0":"amortization","1":"data","2":"easy","3":"kingofnumbers","4":"ltime65","5":"order","6":"taran_1407"},"editorial_url":"https://discuss.codechef.com/problems/WEIRD2","time":{"view_start_date":1540659601,"submit_start_date":1540659601,"visible_start_date":1540659601,"end_date":1735669800},"is_direct_submittable":false,"layout":"problem"}
---
<span class="solution-visible-txt">All submissions for this problem are available.</span>###Read problems statements [Mandarin](http://www.codechef.com/download/translated/LTIME65/mandarin/WEIRD2.pdf) , [Bengali](http://www.codechef.com/download/translated/LTIME65/bengali/WEIRD2.pdf) , [Hindi](http://www.codechef.com/download/translated/LTIME65/hindi/WEIRD2.pdf) , [Russian](http://www.codechef.com/download/translated/LTIME65/russian/WEIRD2.pdf) and [Vietnamese](http://www.codechef.com/download/translated/LTIME65/vietnamese/WEIRD2.pdf) as well.
You are given an integer sequence $A$ with length $N$. Find the number of ordered pairs of positive integers $(a, b)$ such that $a$ occurs in $A$ at least $b$ times and $b$ occurs in $A$ at least $a$ times.
### Input
- The first line of the input contains a single 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$.
- The second line contains $N$ space-separated integers $A_1, A_2, \dots, A_N$.
### Output
For each test case, print a single line containing one integer — the number of pairs.
### Constraints
- $1 \le T \le 1,000$
- $2 \le N \le 10^6$
- $1 \le A_i \le 10^6$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $3 \cdot 10^6$
### Subtasks
**Subtask #1 (30 points):**
- $1 \le N \le 10^5$
- the sum of $N$ over all test cases does not exceed $3 \cdot 10^5$
**Subtask #2 (70 points):** original constraints
### Example Input
```
3
5
1 2 3 4 5
5
1 1 2 2 3
5
3 3 2 2 2
```
### Example Output
```
1
4
3
```