#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5, MOD1 = 1e9 + 7, MOD2 = 1e9 + 207, base1 = 3e5 + 17,
                base2 = 3e5 + 19;
;
long long basePow1[N], basePow2[N], res, a[N], n;
struct THash {
  long long val1, val2, len = 0;
  THash() { val1 = val2 = len = 0; }
  void add(long long x) {
    val1 = (val1 + basePow1[len] * x) % MOD1;
    val2 = (val2 + basePow2[len] * x) % MOD2;
    len++;
  }
  void pop(long long x) {
    len--;
    val1 = (val1 - basePow1[len] * x + MOD1 * MOD1) % MOD1;
    val2 = (val2 - basePow2[len] * x + MOD2 * MOD2) % MOD2;
  }
  bool operator<(THash other) const {
    return (len < other.len && val1 < other.val1 && val2 < other.val2);
  }
};
void get(long long l, long long r) {
  if (l > r) return;
  long long mid = (l + r) >> 1;
  map<tuple<long long, long long, long long>, long long> cnt;
  cnt.clear();
  stack<long long> st;
  while (!st.empty()) st.pop();
  THash cur;
  for (long long i = mid; i >= l; --i) {
    if (st.size() > 0 && st.top() == a[i]) {
      st.pop();
      cur.pop(a[i]);
    } else {
      st.push(a[i]);
      cur.add(a[i]);
    }
    tuple<long long, long long, long long> mt =
        make_tuple(cur.val1, cur.val2, cur.len);
    cnt[mt]++;
  }
  cur = THash();
  while (!st.empty()) st.pop();
  long long tmp = 0;
  for (long long i = mid + 1; i <= r; ++i) {
    if (st.size() > 0 && st.top() == a[i]) {
      st.pop();
      cur.pop(a[i]);
    } else {
      st.push(a[i]);
      cur.add(a[i]);
    }
    tuple<long long, long long, long long> mt =
        make_tuple(cur.val1, cur.val2, cur.len);
    tmp += cnt[mt];
  }
  res += tmp;
  if (l == r) return;
  get(l, mid);
  get(mid + 1, r);
}
void solve() {
  res = 0;
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  get(1, n);
  cout << res << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  basePow1[0] = 1;
  for (long long i = 1; i < N; ++i)
    basePow1[i] = basePow1[i - 1] * base1 % MOD1;
  basePow2[0] = 1;
  for (long long i = 1; i < N; ++i)
    basePow2[i] = basePow2[i - 1] * base2 % MOD2;
  long long q;
  cin >> q;
  while (q--) solve();
  return 0;
}
