# 自己的样例全部通过,传上去case就是通过0
T = int(input())
N = []
L = [] for i in range(T):
n = int(input())
l = list(input().strip().split()) # 字母转数字 l = [c.replace('A', '1') for c in l]
l = [c.replace('J', '11') for c in l]
l = [c.replace('Q', '12') for c in l]
l = [c.replace('K', '13') for c in l]
l = [int(c) for c in l]
l.sort()
N.append(n)
L.append(l) for i in range(T):
n = N[i]
l = L[i]
result = {} # 统计每个数字个数 for j in set(l):
result[j] = l.count(j)
l_ = [] for j in result.keys():
l_.append(j)
l_.sort()
sum = 0 for length in range(4,len(l_)): # 不同顺子长度 for j in range(len(l_)-length): if l_[j] + length == l_[j+length]: # 判断是否是顺子 s = 1 # 计算同种顺子个数 for k in range(length):
s *= result[l_[j+k]]
sum += s print(sum)
#网易##网易互娱##笔试题目#