#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x < y ? x : y;
}
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
const int N = 300010;
int a[N], f[N], rt[N];
struct SegmentTree {
  const static int M = N * 40;
  int tot, lc[M], rc[M], val[M];
  void Init() { tot = 0; }
  int ins(int k, int l, int r, int x, int v) {
    int ret = ++tot;
    lc[ret] = lc[k], rc[ret] = rc[k], val[ret] = 0;
    if (l == r) return val[ret] = v, ret;
    int mid = (l + r) >> 1;
    if (x <= mid)
      lc[ret] = ins(lc[k], l, mid, x, v);
    else
      rc[ret] = ins(rc[k], mid + 1, r, x, v);
    return ret;
  }
  int query(int k, int l, int r, int x) {
    if (!k) return 0;
    if (l == r) return val[k];
    int mid = (l + r) >> 1;
    if (x <= mid) return query(lc[k], l, mid, x);
    return query(rc[k], mid + 1, r, x);
  }
} T;
void solve() {
  int n;
  read(n), T.Init();
  long long ans = 0;
  for (int i = 1; i <= n; i++) read(a[i]), f[i] = 0;
  for (int i = 1; i <= n; i++) {
    int t = T.query(rt[i - 1], 1, n, a[i]);
    if (t) t--, f[i] = f[t] + 1;
    ans += f[i], rt[i] = T.ins(rt[t], 1, n, a[i], i);
  }
  cout << ans << '\n';
}
int main() {
  int Q;
  read(Q);
  while (Q--) solve();
  return 0;
}
