find-pairs

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

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
for _ in range(eval(input())):
	n=eval(input())
	arr=list(map(int,input().split()))
	count=0
	i=0
	j=0
	l=len(arr)
	while i<l:
		j=i
		while j<l:
			if arr[i]==arr[j]:
				count+=1
			j=j+1
		i=i+1
	print(count)


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=eval(input())
for _ in range(0,t):
	c=0
	n=eval(input())
	a=list(map(int,input().split()))
	for i in range(0,n):
		for j in range(i,n):
			if(a[i]==a[j]):
				c+=1
	print(c)


cases = (int)(input(""))
lis=[]
for i in range(cases):
	n = (int)(input(""))
	s = input("")
	arr= list(map(int, s.split()))
	count=0
	for i in range(n):
		for j in range(n):
			if j>=i and arr[i]==arr[j]:
				count=count+1
	print(count)
			
			
   
	
	


count=0
s=""
arr=[]
index=0
test=eval(input())
for t in range(test):
	count=0
	arr=[]
	n=eval(input())
	s=input()+" "
	d=''
	for i in s:        
		if i.isdigit() or (i is '-'):
			d+=i
		else:
			arr.append(int(d))
			d=''
	for i in range(n):
		for j in range(i,n):
			if arr[i]==arr[j]:
				count+=1
				
	print(count)


for tc in range(int(eval(input()))):
	n=int(eval(input()))
	a=list(map(int,input().split()))
	count=0
	for i,j in enumerate(a):
		count+=a[i:].count(j)
	print(count)	
	


noc = eval(input())
while noc:
	noc-=1

	cnt = 0
	one = 10000001*[0]
	two = 10000001*[0]
	nos = eval(input())
	count = 0
	ins = list(map(int,input().split()))
	for i in range(nos):
		a = ins[i]
		if a >= 0:
			one[a]+=1
			count+=one[a]
		else:
			a = a *-1
			two[a]+=1
			count+=two[a]
	print(count)		




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


for _ in range(int(input())):
	n=int(input())
	li=[int(i) for i in input().split()]
	sum=0
	for i in range(n):
		for j in range(i,n):
			if li[i]==li[j]:
				sum+=1
	print(sum)


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int,input().split()))
	cnt=0
	for i in range(n):
		for j in range(i,n):
			if(a[i]==a[j]):
				cnt+=1
	print(cnt)


for _ in range(eval(input())):
	n=eval(input())
	x=list(map(int,input().split()))
	s=0
	while(len(x)>0):
		l=x.count(x[0])
		s+=l
		del x[0]

	print(s)


for _ in range(eval(input())):
	x=eval(input())
	array=list(map(int,input().split()))
	ans =0
	for i in range(len(array)-1):
		for j in range(i+1,len(array)):
			if(array[i]==array[j]):
				ans+=1
	print(len(array)+ans)