#include <bits/stdc++.h>
using namespace std;
long long ar[1000000 + 9];
long long POW1[1000000 + 9];
long long POW2[1000000 + 9];
pair<long long, long long> KEEP[1000000 + 9];
map<pair<long long, long long>, long long> mymap;
struct data {
  long long a, b, val;
};
vector<data> vec;
long long query(int beg, int end) {
  if (beg == end) return 0;
  int mid = (beg + end) >> 1;
  long long ans, i, val, a, b, len;
  ans = query(beg, mid) + query(mid + 1, end);
  vec.clear();
  mymap.clear();
  for (i = mid; i >= beg; i--) {
    if (vec.size() && vec[vec.size() - 1].val == ar[i]) {
      vec.pop_back();
      a = 0;
      b = 0;
      if (vec.size()) a = vec[vec.size() - 1].a;
      if (vec.size()) b = vec[vec.size() - 1].b;
    } else {
      a = 0;
      b = 0;
      if (vec.size()) a = vec[vec.size() - 1].a;
      if (vec.size()) b = vec[vec.size() - 1].b;
      len = vec.size() + 1;
      a += ar[i] * POW1[len];
      b += ar[i] * POW2[len];
      a %= 1000000007;
      b %= 1000000007;
      data curr;
      curr.a = a;
      curr.b = b;
      curr.val = ar[i];
      vec.push_back(curr);
    }
    val = mymap[make_pair(a, b)];
    mymap[make_pair(a, b)] = val + 1;
  }
  vec.clear();
  for (i = mid + 1; i <= end; i++) {
    if (vec.size() && vec[vec.size() - 1].val == ar[i]) {
      vec.pop_back();
      a = 0;
      b = 0;
      if (vec.size()) a = vec[vec.size() - 1].a;
      if (vec.size()) b = vec[vec.size() - 1].b;
    } else {
      a = 0;
      b = 0;
      if (vec.size()) a = vec[vec.size() - 1].a;
      if (vec.size()) b = vec[vec.size() - 1].b;
      len = vec.size() + 1;
      a += ar[i] * POW1[len];
      b += ar[i] * POW2[len];
      a %= 1000000007;
      b %= 1000000007;
      data curr;
      curr.a = a;
      curr.b = b;
      curr.val = ar[i];
      vec.push_back(curr);
    }
    val = mymap[make_pair(a, b)];
    ans += val;
  }
  return ans;
}
int main() {
  long long i, j, k, l, n, m = 0, tot, temp, curr, val, prev, a, b, c, t, ans,
                           expon, flag, x, y, siz, w, h, d, ii, jj, xx, yy, ind,
                           len, max_n, q, s, f, g;
  POW1[0] = POW2[0] = 1;
  for (i = 1; i <= 1000000; i++) POW1[i] = (POW1[i - 1] * 31) % 1000000007;
  for (i = 1; i <= 1000000; i++) POW2[i] = (POW2[i - 1] * 37) % 1000000007;
  cin >> q;
  while (q--) {
    scanf("%lld", &n);
    for (i = 1; i <= n; i++) scanf("%lld", &ar[i]);
    ans = query(1, n);
    printf("%lld\n", ans);
  }
}
