#include <bits/stdc++.h>
using namespace std;
const unsigned long long seed = 1e9 + 9;
unordered_map<unsigned long long, int> mm;
unsigned long long p[333333];
int st[333333], top;
int main() {
  p[0] = 1;
  for (int i = 1; i < 333333; i++) p[i] = p[i - 1] * seed;
  int t;
  scanf("%d", &t);
  while (t--) {
    mm.clear();
    top = 0;
    unsigned long long nowhash = 0;
    int n, a;
    scanf("%d", &n);
    mm[0]++;
    for (int i = 1; i < n + 1; i++) {
      scanf("%d", &a);
      if (top && st[top - 1] == a)
        top--, nowhash -= a * p[top];
      else
        nowhash += a * p[top], st[top++] = a;
      mm[nowhash]++;
    }
    long long res = 0;
    for (auto &k : mm) res += k.second * 1ll * (k.second - 1) / 2;
    printf("%I64d\n", res);
  }
}
