from collections import defaultdict
def II():
return int(input())
def read(v):
return list(map(int, input().split()))
def main():
T = II()
while T > 0:
T -= 1
n = II()
v = read([0]*n)
ab = defaultdict(int)
bc = defaultdict(int)
ac = defaultdict(int)
ab3 = defaultdict(int)
bc3 = defaultdict(int)
ac3 = defaultdict(int)
ans = 0
for i in range(n - 2):
a = v[i]
b = v[i + 1]
c = v[i + 2]
ab[(a, b)] += 1
bc[(b, c)] += 1
ac[(a, c)] += 1
triple = [a, b, c]
ab3[tuple(triple)] += 1
bc3[tuple(triple)] += 1
ac3[tuple(triple)] += 1
ans += ab[(a, b)] - ab3[tuple(triple)]
ans += bc[(b, c)] - bc3[tuple(triple)]
ans += ac[(a, c)] - ac3[tuple(triple)]
print(ans)
if __name__ == "__main__":
main()
1472B - Fair Division | 1281C - Cut and Paste |
141A - Amusing Joke | 112A - Petya and Strings |
677A - Vanya and Fence | 1621A - Stable Arrangement of Rooks |
472A - Design Tutorial Learn from Math | 1368A - C+= |
450A - Jzzhu and Children | 546A - Soldier and Bananas |
32B - Borze | 1651B - Prove Him Wrong |
381A - Sereja and Dima | 41A - Translation |
1559A - Mocha and Math | 832A - Sasha and Sticks |
292B - Network Topology | 1339A - Filling Diamonds |
910A - The Way to Home | 617A - Elephant |
48A - Rock-paper-scissors | 294A - Shaass and Oskols |
1213A - Chips Moving | 490A - Team Olympiad |
233A - Perfect Permutation | 1360A - Minimal Square |
467A - George and Accommodation | 893C - Rumor |
227B - Effective Approach | 1534B - Histogram Ugliness |