#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
const long double pi = acos(-1.0);
int n, a[300300], tp, sta[300300];
map<unsigned long long, int> mp;
unsigned long long hsh[300300];
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}
int main() {
  int T = read();
  while (T--) {
    n = read();
    for (register int i = 1; i <= n; i++) a[i] = read();
    tp = 0;
    long long ans = 0;
    mp.clear();
    mp[0] = 1;
    for (register int i = 1; i <= n; i++) {
      if ((tp) && (sta[tp] == a[i]))
        tp--;
      else {
        sta[++tp] = a[i];
        hsh[tp] = hsh[tp - 1] * 300007 + a[i];
      }
      ans += mp[hsh[tp]];
      mp[hsh[tp]]++;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
