#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const long long mod1 = 998244353;
const long long mod2 = 1e9 + 7;
const long long sd1 = 3e5 + 5;
const long long sd2 = 19260817;
int Q;
int n, a[N], fa[N];
pair<long long, long long> base[N], h[N], hq[N];
map<pair<long long, long long>, int> id;
map<pair<long long, long long>, int>::iterator it;
set<int> p[N];
pair<long long, long long> add_back(pair<long long, long long> val, int x) {
  return make_pair((val.first * sd1 + x + mod1) % mod1,
                   (val.second * sd2 + x + mod2) % mod2);
}
int main() {
  base[0].first = base[0].second = 1;
  for (int i = 1; i < N; ++i) {
    base[i].first = base[i - 1].first * sd1 % mod1;
    base[i].second = base[i - 1].second * sd2 % mod2;
  }
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    static int q[N], mx[N], top, tot;
    for (int i = 1; i <= tot; ++i) p[i].clear();
    id.clear();
    top = tot = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == q[top]) {
        --top;
        h[i] = hq[top];
      } else {
        q[++top] = a[i];
        h[i] = hq[top] = add_back(hq[top - 1], a[i]);
      }
      if (!id[h[i]]) id[h[i]] = ++tot;
      p[id[h[i]]].insert(i);
    }
    pair<long long, long long> val;
    top = 0;
    for (int i = 1; i <= n; ++i) {
      mx[i] = p[id[h[i - 1]]].size() ? *p[id[h[i - 1]]].begin() : -1;
      p[id[h[i]]].erase(i);
    }
    static long long f[N];
    long long ans = 0;
    for (int i = 1; i <= n; ++i) f[i] = 0;
    for (int i = 1; i <= n; ++i) {
      if (~mx[i]) f[mx[i]] += f[i - 1] + 1;
      ans += f[i];
    }
    printf("%I64d\n", ans);
  }
}
