------
## 最终结论
```python
def count_exterminable_subarrays(n, a):
    count = 0
    for start in range(n):
        stack = []
        for end in range(start, n):
            if stack and stack[-1] == a[end]:
                stack.pop()
            else:
                stack.append(a[end])
            if len(stack) == 0:
                count += 1
    return count

q = int(input())
for _ in range(q):
    n = int(input())
    a = list(map(int, input().split()))
    
    count = 0
    for start in range(n):
        stack = []
        for end in range(start, n):
            if stack and stack[-1] == a[end]:
                stack.pop()
            else:
                stack.append(a[end])
            if len(stack) == 0:
                count += 1
                
    print(count)
```