#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5) + 12, mod = int(1e9) + 7;
long long d[N], ans;
int n, a[N], T, last[N], pref[N];
map<int, int> ma[N];
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = i - 1;
    if (a[x] != a[i]) {
      if (ma[x].count(a[i]))
        x = ma[x][a[i]];
      else
        x = 0;
    }
    if (x > 0) {
      d[i] = d[x - 1] + 1;
      ma[i].swap(ma[x - 1]);
      ma[i][a[x - 1]] = x - 1;
    }
    last[a[i]] = i;
    ans += d[i];
  }
  printf("%lld\n", ans);
  for (int i = 0; i <= n; i++) {
    last[i] = 0, d[i] = 0, ans = 0, pref[i] = 0;
    ma[i].clear();
  }
}
int main() {
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
