#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return s * w;
}
int q, n;
int a[300010], nxt[300010], dp[300010];
map<int, int> nxtX[300010];
int main() {
  q = read();
  while (q--) {
    n = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int i = 1; i <= n + 3; i++) nxt[i] = -1, nxtX[i].clear(), dp[i] = 0;
    for (int i = n; i >= 1; i--) {
      if (nxtX[i + 1].count(a[i])) {
        int pos = nxtX[i + 1][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; i >= 1; i--) {
      if (nxt[i] == -1) continue;
      dp[i] = 1 + dp[nxt[i] + 1];
      ans += dp[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
