find-pairs-1
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j].

First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A.

For each test case print the number of distinct pairs.

Constraints

1 ≤ T ≤ 10

1 ≤ N ≤ 10^6 

-10^6 ≤ A[i] ≤ 10^6 for 0 ≤ i < N

SAMPLE INPUT
2
4
1 2 3 4
3
1 2 1

SAMPLE OUTPUT
4
4


t=eval(input())
for _ in range(t):
	n=eval(input())
	a=list(map(int,input().split()))
	c=0
	for i in range(0,len(a)-1):
		for j in range(i,len(a)):
			if a[i]==a[j]:
				c+=1
	print(c+1)
				


if __name__=='__main__':
	T = int(input())
	for i in range(0,T):
		t = int(input())
		numlist = list(map(int,input().split()))
		count = 0
		for k in range(0,t):
			for j in range(k+1,t):
				if numlist[k]==numlist[j]:
					count += 1
		print(count+t)


t=eval(input())
while(t>0):
	n=eval(input())
	a=input().split()
	c=0
	for i in range(n):
		for j in range(n):
			if(j>=i and a[i]==a[j]):
				c+=1
	print(c)
	t=t-1


if __name__=='__main__':
	T = int(input())
	for i in range(0,T):
		t = int(input())
		numlist = list(map(int,input().split()))
		count = 0
		for k in range(0,t):
			for j in range(k+1,t):
				if numlist[k]==numlist[j]:
					count += 1
		print(count+t)


for _ in range(eval(input())):
	n,m=eval(input()),0
	a=list(map(int,input().split()))
	for x in range(n):
		z=a[x:]
		m=m+z.count(a[x])
	print(m)
		


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import collections
n = int(input())
for _ in range(n):
	m = int(input())
	l = list(map(int,input().split()))
	k = dict(collections.Counter(l))
	result = len(l)
	temp = [(k[i]-1)*k[i]/2 for i in list(k.keys()) if k[i]!=1]
	result = result + sum(temp)
	print(result)