#include <bits/stdc++.h>
using namespace std;
map<long long, long long> C[303030];
long long A[303030], P[303030], V[303030];
long long n, ans;
void dnc(long long s, long long e) {
  if (s >= e) return;
  vector<long long> X;
  long long m, i, p, t, x;
  m = s + e >> 1;
  p = 1;
  t = 1;
  for (i = m; i >= s; i--) {
    if (X.empty() || X.back() != A[i]) {
      X.push_back(A[i]);
      if (C[t].find(A[i]) == C[t].end()) {
        C[t][A[i]] = ++p;
        x = p;
      } else
        x = C[t][A[i]];
      P[x] = t;
      t = x;
    } else {
      X.pop_back();
      t = P[t];
    }
    V[t]++;
  }
  X.clear();
  t = 1;
  for (i = m + 1; i <= e; i++) {
    if (X.empty() || X.back() != A[i]) {
      X.push_back(A[i]);
      if (C[t].find(A[i]) == C[t].end()) {
        C[t][A[i]] = ++p;
        x = p;
      } else
        x = C[t][A[i]];
      P[x] = t;
      t = x;
    } else {
      X.pop_back();
      t = P[t];
    }
    ans += V[t];
  }
  for (i = 1; i <= p; i++) {
    C[i].clear();
    V[i] = 0;
  }
  dnc(s, m);
  dnc(m + 1, e);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long q, i;
  cin >> q;
  for (; q--;) {
    cin >> n;
    for (i = 1; i <= n; i++) {
      cin >> A[i];
    }
    ans = 0;
    dnc(1, n);
    cout << ans << "\n";
  }
  return 0;
}
