#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  b %= mod;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
struct Roller {
  vector<long long> vals;
  long long hashval = 0;
  long long curmul;
  long long B, invB, Mod;
  void init(long long _B, long long _Mod) {
    curmul = 1;
    Mod = _Mod;
    B = _B;
    invB = binpow(B, Mod - 2, Mod);
  }
  void append(long long x) {
    long long temp = x * curmul % Mod;
    vals.emplace_back(temp);
    hashval = (hashval + temp) % Mod;
    curmul = (B * curmul) % Mod;
  }
  void remove() {
    hashval += (Mod - vals.back());
    hashval %= Mod;
    vals.pop_back();
    curmul = curmul * invB % Mod;
  }
};
struct DoubleHash {
  Roller h1, h2;
  DoubleHash() { h1.init(3121424, 999999937), h2.init(3244353, 999999929); }
  void append(long long x) {
    h1.append(x);
    h2.append(x);
  }
  void remove() {
    h1.remove();
    h2.remove();
  }
  pair<long long, long long> get() { return make_pair(h1.hashval, h2.hashval); }
};
long long ans = 0;
long long n;
vector<long long> arr;
void rec(long long l, long long r) {
  if (r - l + 1 <= 1) return;
  int mid = (l + r) >> 1;
  rec(l, mid);
  rec(mid + 1, r);
  vector<long long> lefstack;
  DoubleHash lef;
  map<pair<long long, long long>, long long> freq;
  for (int i = mid; i >= l; i--) {
    if (lefstack.empty() || lefstack.back() != arr[i]) {
      lefstack.emplace_back(arr[i]);
      lef.append(arr[i]);
    } else {
      lefstack.pop_back();
      lef.remove();
    }
    freq[lef.get()]++;
  }
  vector<long long> rightstack;
  DoubleHash rig;
  for (int i = mid + 1; i <= r; i++) {
    if (rightstack.empty() || rightstack.back() != arr[i]) {
      rightstack.emplace_back(arr[i]);
      rig.append(arr[i]);
    } else {
      rightstack.pop_back();
      rig.remove();
    }
    ans += freq[rig.get()];
  }
}
void solve() {
  ans = 0;
  cin >> n;
  arr.resize(n);
  for (long long i = 0; i < (n); ++i) cin >> arr[i];
  rec(0, n - 1);
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long _t = 1;
  cin >> _t;
  for (long long i = 1; i <= _t; i++) {
    solve();
  }
}
