#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll work(const vector<int> &a, const int l, const int r) {
  if (r - l == 1) return 0LL;
  const int m = (l + r) / 2;
  ll ans = work(a, l, m) + work(a, m, r);
  using ull = unsigned long long;
  vector<ull> cost(max(r - m, m - l));
  static mt19937_64 rng;
  for (auto &it : cost) it = rng() * 2ULL + 1ULL;
  vector<int> stck;
  ull cur_hash = 0;
  auto append = [&](int x) {
    if (stck.empty() || stck.back() != x) {
      stck.push_back(x);
      cur_hash += cost[int(stck.size()) - 1] * x;
    } else {
      cur_hash -= cost[int(stck.size()) - 1] * x;
      stck.pop_back();
    }
  };
  vector<ull> hashes;
  for (int i = m - 1; i >= l; i--) {
    append(a[i]);
    hashes.push_back(cur_hash);
  }
  cur_hash = 0;
  stck.clear();
  sort(hashes.begin(), hashes.end());
  for (int i = m; i < r; i++) {
    append(a[i]);
    auto pr = equal_range(hashes.begin(), hashes.end(), cur_hash);
    assert(pr.first <= pr.second);
    ans += pr.second - pr.first;
  }
  return ans;
}
void solve_test(istream &cin = std::cin, ostream &cout = std::cout) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &it : a) cin >> it;
  cout << work(a, 0, n) << endl;
}
void solve(istream &cin = std::cin, ostream &cout = std::cout) {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) solve_test(cin, cout);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
