#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 5;
const int inf = (int)1e9 + 7;
int q;
int n;
int a[N];
int nxt[N];
long long dp[N];
map<int, int> nxtx[N];
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    nxtx[i].clear();
    nxt[i] = -1;
    dp[i] = 0;
  }
  dp[n + 1] = 0;
  nxtx[n + 1].clear();
  for (int i = n; i >= 1; --i) {
    if (nxtx[i + 1].count(a[i])) {
      nxt[i] = nxtx[i + 1][a[i]];
      swap(nxtx[i], nxtx[nxt[i] + 1]);
      if (nxt[i] < n) {
        nxtx[i][a[nxt[i] + 1]] = nxt[i] + 1;
      }
    }
    nxtx[i][a[i]] = i;
  }
  long long ans = 0;
  for (int i = n; i >= 1; --i) {
    if (nxt[i] != -1) {
      dp[i] = dp[nxt[i] + 1] + 1;
      ans += dp[i];
    }
  }
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &q);
  while (q--) {
    solve();
  }
  return 0;
}
