#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int mod = 1000003273;
const int N = 500005;
const int M = 500057;
int n, a[600005], p[600005], pw[600005];
long long ans;
vector<pair<int, int>> v;
map<pair<int, int>, int> m;
void add(int x) {
  v.push_back(make_pair(x, ((long long)pw[(int)v.size()] * x +
                            ((int)v.size() ? v.back().second : 0)) %
                               mod));
}
void del() {
  if ((int)v.size()) v.pop_back();
}
void rec(int l = 1, int r = n) {
  if (l == r) return;
  int tm = (l + r) / 2;
  m.clear();
  v.clear();
  for (int i = tm; i >= l; i--) {
    if ((int)v.size() && v.back().first == a[i])
      del();
    else
      add(a[i]);
    if ((int)v.size())
      m[make_pair(v.back().second, (int)v.size())]++;
    else
      m[make_pair(0, 0)]++;
  }
  v.clear();
  for (int i = tm + 1; i <= r; i++) {
    if ((int)v.size() && v.back().first == a[i])
      del();
    else
      add(a[i]);
    if ((int)v.size())
      ans += m[make_pair(v.back().second, (int)v.size())];
    else
      ans += m[make_pair(0, 0)];
  }
  rec(l, tm);
  rec(tm + 1, r);
}
void solve() {
  ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  rec();
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.precision(30);
  cerr.precision(7);
  ;
  pw[0] = M;
  for (int i = 1; i <= N; i++) pw[i] = ((long long)pw[i - 1] * M) % mod;
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
