#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const long long mod1 = 201326611, mod2 = 402653189, base1 = 50331653,
                base2 = 100663319;
long long pow1[N], pow2[N];
int a[N];
long long solve(int l, int r) {
  if (l >= r) return 0;
  int mid = (l + r) / 2;
  long long ans = solve(l, mid) + solve(mid + 1, r);
  stack<tuple<int, long long, long long>> stk;
  stk.push(make_tuple(0, 0, 0));
  vector<pair<long long, long long>> right_hash, left_hash;
  for (int i = mid + 1; i <= r; i++) {
    int x = a[i];
    if (get<0>(stk.top()) == x)
      stk.pop();
    else {
      long long h1 = get<1>(stk.top());
      long long h2 = get<2>(stk.top());
      h1 = (h1 * base1 + x) % mod1;
      h2 = (h2 * base2 + x) % mod2;
      stk.push(make_tuple(x, h1, h2));
    }
    right_hash.push_back(make_pair(get<1>(stk.top()), get<2>(stk.top())));
  }
  sort(right_hash.begin(), right_hash.end());
  while (stk.size() > 0) stk.pop();
  stk.push(make_tuple(0, 0, 0));
  for (int i = mid; i >= l; i--) {
    int x = a[i];
    if (get<0>(stk.top()) == x)
      stk.pop();
    else {
      long long h1 = get<1>(stk.top());
      long long h2 = get<2>(stk.top());
      h1 = (h1 * base1 + x) % mod1;
      h2 = (h2 * base2 + x) % mod2;
      stk.push(make_tuple(x, h1, h2));
    }
    left_hash.push_back(make_pair(get<1>(stk.top()), get<2>(stk.top())));
  }
  for (int i = 0; i < left_hash.size(); i++) {
    pair<long long, long long> t = left_hash[i];
    ans += upper_bound(right_hash.begin(), right_hash.end(), t) -
           lower_bound(right_hash.begin(), right_hash.end(), t);
  }
  return ans;
}
void init() {
  pow1[0] = pow2[0] = 1;
  for (int i = 1; i < N; i++) {
    pow1[i] = (pow1[i - 1] * base1) % mod1;
    pow2[i] = (pow2[i - 1] * base2) % mod2;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  init();
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    cout << solve(1, n) << "\n";
  }
  return 0;
}
