#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int Q, n, a[maxn], nxt[maxn], id[maxn], f[maxn];
map<int, int> h[maxn];
long long ans;
int get(int x, int y) {
  if (h[x].find(y) == h[x].end())
    return -1;
  else
    return h[x][y];
}
int main() {
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
      scanf("%d", &a[i]), h[i].clear(), f[i] = 0, nxt[i] = -1;
    id[n + 1] = n + 1, nxt[n + 1] = -1, f[n + 1] = 0;
    h[n + 1].clear();
    for (int i = n; i >= 1; i--) {
      nxt[i] = get(id[i + 1], a[i]);
      if (nxt[i] != -1)
        id[i] = id[nxt[i] + 1];
      else
        id[i] = i;
      h[id[i]][a[i]] = i;
    }
    ans = 0;
    for (int i = n; i >= 1; i--)
      if (nxt[i] != -1) f[i] = f[nxt[i] + 1] + 1, ans += 1ll * f[i];
    printf("%lld\n", ans);
  }
  return 0;
}
