#include <bits/stdc++.h>
const int N = 300005;
int n, a[N];
long long ans, dp[N];
std::map<int, int> nxt[N];
void solve() {
  std::cin >> n, ans = 0;
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  for (int i = n; i; --i) {
    int p = 0;
    if (nxt[i + 1].count(a[i])) p = nxt[i + 1][a[i]] + 1;
    if (p) std::swap(nxt[i], nxt[p]);
    if (p) ans += dp[i] = dp[p] + 1;
    nxt[i][a[i]] = i;
  }
  for (int i = 1; i <= n + 1; ++i) nxt[i].clear(), dp[i] = 0;
  std::cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  int tc;
  std::cin >> tc;
  while (tc--) solve();
  return 0;
}
