#include <bits/stdc++.h>
using namespace std;
int a[300001];
int f[300001];
map<int, int> F[300001];
long long work() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    F[i].clear();
    f[i] = 0;
    cin >> a[i];
    if (F[i - 1].count(a[i])) {
      f[i] = F[i - 1][a[i]];
      F[i].swap(F[f[i] - 1]);
      if (f[i] > 1) F[i][a[f[i] - 1]] = f[i] - 1;
    }
    F[i][a[i]] = i;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (f[i]) a[i] = a[f[i] - 1] + 1;
    if (!f[i]) a[i] = 0;
    ans += a[i];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) cout << work() << "\n";
}
