#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& x : a) cin >> x;
  a.push_back(n + 1);
  vector<map<int, int>*> d(n + 1);
  vector<int> pr(n + 1, 0);
  d[n] = new map<int, int>;
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    int trans = -1;
    if (a[i + 1] == a[i])
      trans = i + 2;
    else if (d[i + 1]->find(a[i]) != d[i + 1]->end())
      trans = (*d[i + 1])[a[i]] + 1;
    if (trans == -1)
      d[i] = new map<int, int>;
    else {
      d[i] = d[trans];
      (*d[i])[a[trans]] = trans;
      pr[i] = pr[trans];
      pr[i]++;
    }
    ans += pr[i];
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) solve();
  return 0;
}
