#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long G = 300005, BASE = 666667, M1 = 2e9 + 11, M2 = 1e9 + 9;
long long IB1, IB2;
long long a, o;
long long m[G], pwb1[G], pwb2[G];
long long binpow(long long x, long long k, long long mod) {
  long long res = 1;
  for (; k; k >>= 1) {
    if (k & 1) res = res * x % mod;
    x = x * x % mod;
  }
  return res;
}
long long modInv(long long x, long long mod) { return binpow(x, mod - 2, mod); }
void rec(long long l, long long r) {
  long long d = r - l + 1;
  if (d < 2) return;
  long long md = (l + r) / 2;
  vector<pair<long long, long long> > hl, hr;
  vector<long long> stq;
  for (long long q = md, hs1 = 0, hs2 = 0; q >= l; q--) {
    if (stq.size() && stq.back() == m[q]) {
      hs1 = (hs1 - m[q] + M1) % M1;
      hs1 = hs1 * IB1 % M1;
      hs2 = (hs2 - m[q] + M2) % M2;
      hs2 = hs2 * IB2 % M2;
      stq.pop_back();
    } else {
      stq.push_back(m[q]);
      hs1 = (hs1 * BASE + m[q]) % M1;
      hs2 = (hs2 * BASE + m[q]) % M2;
    }
    hl.push_back({hs1, hs2});
  }
  stq.clear();
  for (long long q = md + 1, hs1 = 0, hs2 = 0; q <= r; q++) {
    if (stq.size() && stq.back() == m[q]) {
      hs1 = (hs1 - m[q] + M1) % M1;
      hs1 = hs1 * IB1 % M1;
      hs2 = (hs2 - m[q] + M2) % M2;
      hs2 = hs2 * IB2 % M2;
      stq.pop_back();
    } else {
      stq.push_back(m[q]);
      hs1 = (hs1 * BASE + m[q]) % M1;
      hs2 = (hs2 * BASE + m[q]) % M2;
    }
    hr.push_back({hs1, hs2});
  }
  sort(hl.begin(), hl.end());
  sort(hr.begin(), hr.end());
  for (pair<long long, long long> i : hl) {
    o += upper_bound(hr.begin(), hr.end(), i) -
         lower_bound(hr.begin(), hr.end(), i);
  }
  rec(l, md);
  rec(md + 1, r);
}
long long solve() {
  cin >> a;
  for (int q = 0; q < a; q++) cin >> m[q];
  o = 0;
  rec(0, a - 1);
  return o;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  ;
  IB1 = modInv(BASE, M1);
  IB2 = modInv(BASE, M2);
  pwb1[0] = 1;
  pwb2[0] = 1;
  for (int q = 1; q < G; q++) pwb1[q] = pwb1[q - 1] * BASE % M1;
  for (int q = 1; q < G; q++) pwb2[q] = pwb2[q - 1] * BASE % M2;
  int z;
  cin >> z;
  for (; z--;) {
    cout << solve() << "\n";
  }
}
