#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int T, n, a[N], Nxt[N], dp[N];
map<int, int> nxt[N];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i < n + 2; i++) {
      Nxt[i] = -1;
      nxt[i].clear();
      dp[i] = 0;
    }
    for (int i = n; i; i--) {
      if (nxt[i + 1].count(a[i])) {
        int pos = nxt[i + 1][a[i]];
        Nxt[i] = pos;
        swap(nxt[pos + 1], nxt[i]);
        if (pos < n) nxt[i][a[pos + 1]] = pos + 1;
      }
      nxt[i][a[i]] = i;
    }
    long long ans = 0;
    for (int i = n; i; i--)
      if (Nxt[i] != -1) {
        dp[i] = dp[Nxt[i] + 1] + 1;
        ans += dp[i];
      }
    printf("%lld\n", ans);
  }
}
