# cook your dish here

# Number of testcases…

T = int(input())

# desired number of pairs…

P = {}

if T<=20 and T>=1:

for i in range(T):

# Length of a sequence…

N = int(input())

if N>=1 and N<=40000:

# Sequence…

s = [int(s) for s in input().split()]

# 2nd way …

# s = list(map(int, input().split()))

count = 0

flag = 0

# there is only two pairs which satisfies the following equation Ai+Aj=Ai⋅Aj

# i.e. (0,0) and (2,2)

for m in s:

if m>=0 and m<=10**9:

if m==2:

count+=1

elif m==0:

flag+=1

else:

print(“Invalid input!!!”)

def count_pairs(n):

global d_p

if n%2==0:

# desired pairs

d_p = n/2

elif n%2!=0 and n!=1:

# desired pairs

d_p = ((n-1)/2)*(1+(n-1))

return int(d_p)

pair = count_pairs(count) + count_pairs(flag)

# for output

P[i] = pair

else:

print(‘only upto 20 test_cases are allowed!!!’)

for j in range(T):

print(P.get(j))