#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
unsigned long long h[333333], a[333333];
int stk[333333], n;
map<unsigned long long, int> mp;
void predo() {}
void init() { n = read(); }
void solve() {
  int top = 0;
  h[1] = 0;
  for (int i = (int)1; i <= (int)n; i++) {
    int x = read();
    if (stk[top] == x)
      top--;
    else
      stk[++top] = x, h[top] = h[top - 1] * 19260817 + x;
    a[i] = h[top];
  }
  mp.clear();
  mp[0] = 1;
  long long ans = 0;
  for (int i = (int)1; i <= (int)n; i++) {
    ans += mp[a[i]];
    mp[a[i]]++;
  }
  printf("%lld\n", ans);
}
int main() {
  predo();
  int cas = read();
  while (cas--) {
    init();
    solve();
  }
  return 0;
}
