#include <bits/stdc++.h>
template <class T>
inline bool cmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool cmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
using namespace std;
char ss[1 << 17], *A = ss, *B = ss;
inline char gc() {
  return A == B && (B = (A = ss) + fread(ss, 1, 1 << 17, stdin), A == B) ? -1
                                                                         : *A++;
}
template <class T>
inline void sd(T& x) {
  char c;
  T y = 1;
  while (c = gc(), (c < 48 || 57 < c) && c != -1)
    if (c == 45) y = -1;
  x = c - 48;
  while (c = gc(), 47 < c && c < 58) x = x * 10 + c - 48;
  x *= y;
}
const int N = 3e5 + 5, M = N << 1, inf = ~0u >> 1;
typedef int arr[N];
int n, a[N], Nx[N];
long long f[N];
map<int, int> Ny[N];
inline void sol() {
  sd(n);
  for (register int i = 1, I = n + 1; i < I; ++i) {
    sd(a[i]);
    Ny[i].clear();
    Nx[i] = -1;
    f[i] = 0;
  }
  Ny[n + 1].clear();
  f[n + 1] = 0;
  int p;
  long long ans = 0;
  for (register int i = n, I = 1 - 1; i > I; --i) {
    if (Ny[i + 1].count(a[i])) {
      Nx[i] = p = Ny[i + 1][a[i]];
      swap(Ny[i], Ny[p + 1]);
      if (p != n) Ny[i][a[p + 1]] = p + 1;
    }
    Ny[i][a[i]] = i;
  }
  for (register int i = n, I = 1 - 1; i > I; --i)
    if (~Nx[i]) {
      f[i] = f[Nx[i] + 1] + 1;
      ans += f[i];
    }
  printf("%lld\n", ans);
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) sol();
  return 0;
}
