#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 4e5;
const long long P = 1e6 + 3;
const long long M1 = 1e7 + 21;
const long long M2 = 1e7 + 33;
long long pw1[N], pw2[N];
struct st {
  vector<long long> a;
  long long h1, h2;
  void clear() {
    h1 = 0;
    h2 = 0;
    a.clear();
  }
  st() { clear(); }
  long long back() {
    if (a.empty()) {
      return -1;
    }
    return a.back();
  }
  void push(long long v) {
    h1 = (h1 + v * pw1[a.size()]) % M1;
    h2 = (h2 + v * pw2[a.size()]) % M2;
    a.push_back(v);
  }
  void pop() {
    long long v = a.back();
    a.pop_back();
    h1 = (h1 - v * pw1[a.size()] + M1 * M1) % M1;
    h2 = (h2 - v * pw2[a.size()] + M2 * M2) % M2;
  }
  long long value() { return (h1 << 32) + h2; }
};
long long n, a[N];
st sta;
long long dc(long long l, long long r) {
  if (r - l <= 1) {
    return 0;
  }
  long long m = (l + r) / 2;
  long long answer = dc(l, m) + dc(m, r);
  map<long long, long long> cnt;
  sta.clear();
  for (long long i = m; i < r; ++i) {
    if (sta.back() == a[i]) {
      sta.pop();
    } else {
      sta.push(a[i]);
    }
    ++cnt[sta.value()];
  }
  sta.clear();
  for (long long i = m - 1; i >= l; --i) {
    if (sta.back() == a[i]) {
      sta.pop();
    } else {
      sta.push(a[i]);
    }
    answer += cnt[sta.value()];
  }
  return answer;
}
long long solve() {
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  return dc(0, n);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  pw1[0] = 1;
  pw2[0] = 1;
  for (long long i = 1; i < N; ++i) {
    pw1[i] = pw1[i - 1] * P % M1;
    pw2[i] = pw2[i - 1] * P % M2;
  }
  long long q;
  cin >> q;
  while (q--) {
    cout << solve() << "\n";
  }
  return 0;
}
