#include <bits/stdc++.h>
const int kInf = 0x3f3f3f3f, kMod = 1e9 + 7;
const long long kInf64 = 0x3f3f3f3f3f3f3f3f;
template <typename T>
inline void UMin(T& x, const T& y) {
  if (x > y) x = y;
}
template <typename T>
inline void UMax(T& x, const T& y) {
  if (x < y) x = y;
}
inline int Add(int a, int b) { return (a += b) >= kMod ? a - kMod : a; }
inline int Sub(int a, int b) { return (a -= b) < 0 ? a + kMod : a; }
inline int Mul(int a, int b) { return 1ll * a * b % kMod; }
int FPow(int bs, int ex = kMod - 2) {
  int res = 1;
  for (; ex; bs = Mul(bs, bs), ex >>= 1)
    if (ex & 1) res = Mul(res, bs);
  return res;
}
const int kMaxn = 3e5 + 5;
void Solve();
int main() {
  int q;
  scanf("%d", &q);
  while (q--) Solve();
  return 0;
}
int n;
int A[kMaxn], nxt[kMaxn], DP[kMaxn], vis[kMaxn];
std::map<int, int> mp[kMaxn];
void Solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", A + i);
    mp[i].clear();
    DP[i] = 0, nxt[i] = -1;
  }
  mp[n].clear();
  DP[n] = 0, nxt[n] = -1;
  long long ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (mp[i + 1].count(A[i])) nxt[i] = mp[i + 1][A[i]];
    if (~nxt[i]) {
      ans += (DP[i] = DP[nxt[i] + 1] + 1);
      std::swap(mp[i], mp[nxt[i] + 1]);
      if (nxt[i] < n - 1) mp[i][A[nxt[i] + 1]] = nxt[i] + 1;
    }
    mp[i][A[i]] = i;
  }
  printf("%lld\n", ans);
}
