#include <bits/stdc++.h>
using namespace std;
int n;
int a[300005];
int nxt[300005];
long long dp[300005];
map<int, int> nxtX[300005];
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n + 2; i++) {
    nxt[i] = -1;
    nxtX[i].clear();
    dp[i] = 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (nxtX[i + 1].count(a[i])) {
      int pos = nxtX[i + 1][a[i]];
      assert(pos < n && a[pos] == a[i]);
      nxt[i] = pos;
      swap(nxtX[i], nxtX[pos + 1]);
      if (pos < n - 1) {
        nxtX[i][a[pos + 1]] = pos + 1;
      }
    }
    nxtX[i][a[i]] = i;
  }
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (nxt[i] == -1) continue;
    dp[i] = 1 + dp[nxt[i] + 1];
    ans += dp[i];
  }
  printf("%lld\n", ans);
}
int main(void) {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    solve();
  }
  return 0;
}
