#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 200;
const int M = 2e6;
const long long mod = 276500309;
const long long mod1 = 697266329;
const long long mod2 = 478555879;
const int inf = 2e9 + 3;
const long long INF = 1e18;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
void files() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
long long P = 315564;
int T, n, a[N];
stack<pair<int, tuple<long long, long long, long long>>> second;
map<tuple<long long, long long, long long>, long long> was;
tuple<long long, long long, long long> nei = {-1, -1, -1};
long long rec(int l, int r) {
  if (l >= r) return 0;
  long long ans = 0;
  int m = (l + r) / 2;
  was.clear();
  for (int i = m + 1; i <= r; ++i) {
    if (second.empty()) {
      tuple<long long, long long, long long> nval = {a[i], a[i], a[i]};
      second.push({a[i], nval});
    } else {
      if (second.top().first == a[i]) {
        second.pop();
      } else {
        long long A = get<0>(second.top().second);
        long long B = get<1>(second.top().second);
        long long C = get<2>(second.top().second);
        tuple<long long, long long, long long> nval = {
            (A * P + a[i]) % mod, (B * P + a[i]) % mod1, (C * P + a[i]) % mod2};
        second.push({a[i], nval});
      }
    }
    if ((int)second.size())
      was[second.top().second]++;
    else
      was[nei]++;
  }
  while ((int)second.size()) second.pop();
  for (int i = m; i >= l; --i) {
    if (second.empty()) {
      second.push({a[i], {a[i], a[i], a[i]}});
    } else {
      if (second.top().first == a[i]) {
        second.pop();
      } else {
        long long A = get<0>(second.top().second);
        long long B = get<1>(second.top().second);
        long long C = get<2>(second.top().second);
        tuple<long long, long long, long long> nval = {
            (A * P + a[i]) % mod, (B * P + a[i]) % mod1, (C * P + a[i]) % mod2};
        second.push({a[i], nval});
      }
    }
    if ((int)second.size())
      ans += was[second.top().second];
    else
      ans += was[nei];
  }
  while ((int)second.size()) second.pop();
  ans += rec(l, m) + rec(m + 1, r);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    printf("%lld\n", rec(1, n));
  }
}
