from itertools import combinations from collections import Counter from sys import stdin s=stdin.readline() for i in range(int(s)): input() list1=[int(x) for x in input().split()] a=dict(Counter(list1)) ans=sum(a[smal]*a[mid]*a[larg] for smal,mid,larg in combinations(sorted(a),3) if smal**2+mid**2==larg**2) print(ans)