#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000;
const int MOD = 1000 * 1000 * 1000 + 7;
const long long p = 21;
const int MOD1 = 1000 * 1000 * 1000 + 9;
const long long p1 = 17;
long long rev_p = 0;
long long rev_p1 = 0;
int a[MAXN];
long long _pow(long long a, long long p, long long mod) {
  long long ans = 1;
  while (p > 0) {
    if (p & 1) {
      ans = (ans * a) % mod;
    }
    p /= 2;
    a = (a * a) % mod;
  }
  return ans;
}
long long _rev(long long a, long long mod) { return _pow(a, mod - 2, mod); }
long long _do(int l, int r) {
  if (l == r) return 0;
  int s = (l + r) / 2;
  long long ans = 0;
  ans += _do(l, s);
  ans += _do(s + 1, r);
  map<pair<long long, long long>, long long> r_hash;
  {
    vector<int> r_st;
    long long cur_hash = 0;
    long long cur_hash1 = 0;
    for (int i = s + 1; i <= r; i++) {
      if (r_st.empty() || r_st.back() != a[i]) {
        r_st.push_back(a[i]);
        cur_hash = (cur_hash * p + a[i]) % MOD;
        cur_hash1 = (cur_hash1 * p1 + a[i]) % MOD1;
      } else {
        cur_hash = ((cur_hash - a[i] + MOD) * rev_p) % MOD;
        cur_hash1 = ((cur_hash1 - a[i] + MOD1) * rev_p1) % MOD1;
        r_st.pop_back();
      }
      r_hash[{cur_hash, cur_hash1}]++;
    }
  }
  map<pair<long long, long long>, long long> l_hash;
  {
    vector<int> l_st;
    long long cur_hash = 0;
    long long cur_hash1 = 0;
    for (int i = s; i >= l; i--) {
      if (l_st.empty() || l_st.back() != a[i]) {
        l_st.push_back(a[i]);
        cur_hash = (cur_hash * p + a[i]) % MOD;
        cur_hash1 = (cur_hash1 * p1 + a[i]) % MOD1;
      } else {
        cur_hash = ((cur_hash - a[i] + MOD) * rev_p) % MOD;
        cur_hash1 = ((cur_hash1 - a[i] + MOD1) * rev_p1) % MOD1;
        l_st.pop_back();
      }
      l_hash[{cur_hash, cur_hash1}]++;
    }
  }
  for (auto it : l_hash) {
    ans += it.second * r_hash[it.first];
  }
  return ans;
}
void solve() {
  int n;
  scanf("%i", &n);
  for (int i = 0; i < n; i++) {
    scanf("%i", a + i);
  }
  printf("%lld\n", _do(0, n - 1));
}
int main(int argc, const char* argv[]) {
  rev_p = _rev(p, MOD);
  rev_p1 = _rev(p1, MOD1);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    solve();
  }
  return 0;
}
