#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const int maxn = 3e5 + 10, maxm = 1e6 + 10, lg = 22, mod = 1e9 + 7, inf = 1e18;
int n, a[maxn], nx[maxn], dp[maxn];
map<int, int> fnx[maxn];
int main() {
  int T;
  scanf("%d", &T);
  memset(nx, -1, sizeof(nx));
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = n; i; i--) {
      if (fnx[i + 1].count(a[i])) {
        nx[i] = fnx[i + 1][a[i]];
        fnx[i].swap(fnx[nx[i] + 1]);
        if (nx[i] < n) fnx[i][a[nx[i] + 1]] = nx[i] + 1;
      }
      fnx[i][a[i]] = i;
    }
    long long ans = 0;
    for (int i = n; i; i--)
      if (nx[i] != -1) ans += dp[i] = 1 + dp[nx[i] + 1];
    cout << ans << '\n';
    for (int i = 1; i <= n; i++) fnx[i].clear(), dp[i] = 0, nx[i] = -1;
  }
  return 0;
}
