#include <bits/stdc++.h>
using namespace std;
template <typename U, typename V>
void Min(U &a, const V &b) {
  if (a > b) a = b;
}
template <typename U, typename V>
void Max(U &a, const V &b) {
  if (a < b) a = b;
}
template <typename U, typename V>
void add(U &a, const V &b) {
  a = (a + b) % 998244353;
}
template <typename U>
U gcd(U a, U b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a >= b)
    return gcd(a % b, b);
  else
    return gcd(a, b % a);
}
int pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % 998244353;
    a = 1LL * a * a % 998244353;
    b >>= 1;
  }
  return ans;
}
int a[300005], dp[300005], ne[300005], id[300005];
unordered_map<int, int> g[300005];
int main() {
  int T, n, m, i, j, k, ca = 0;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < n + 1; i++) dp[i] = ne[i] = 0, id[i] = i, g[i].clear();
    for (int i = n - 1; i >= 0; i--) {
      k = id[i + 1];
      if (g[k].count(a[i])) {
        ne[i] = g[k][a[i]];
        id[i] = id[ne[i] + 1];
      }
      g[id[i]][a[i]] = i;
    }
    long long ans = 0;
    dp[n] = 0;
    for (int i = n - 1; i >= 0; i--)
      if (ne[i]) {
        dp[i] = dp[ne[i] + 1] + 1;
        ans += dp[i];
      }
    printf("%lld\n", ans);
  }
}
