#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 17, base = 1e9 + 7;
int n, a[maxn];
unsigned long long h[maxn];
map<unsigned long long, int> gen(int l, int r) {
  stack<int> s;
  map<unsigned long long, int> ret;
  for (; l < r; l++) {
    if (s.size() && s.top() == a[l])
      s.pop();
    else {
      s.push(a[l]);
      h[s.size()] = h[s.size() - 1] * base + a[l];
    }
    ret[h[s.size()]]++;
  }
  return ret;
}
long long solve(int l = 0, int r = n) {
  if (l + 1 == r) return 0;
  int mid = (l + r) / 2;
  long long ret = solve(l, mid) + solve(mid, r);
  reverse(a + l, a + mid);
  auto L = gen(l, mid);
  reverse(a + l, a + mid);
  for (auto &[k, v] : gen(mid, r)) {
    ret += (long long)v * L[k];
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int q = 1;
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << solve() << '\n';
  }
}
