#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int res = 0, c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  do {
    res = (res * 10) + (c ^ 48);
  } while (c = getchar(), c >= '0' && c <= '9');
  return res;
}
int s[300010], dp[300010];
map<int, int> R[300010];
int main() {
  int Q = read();
  while (Q--) {
    long long ans = 0;
    int N = read();
    for (int i = 1; i <= N + 2; i++) {
      if (i <= N) s[i] = read();
      dp[i] = 0;
      R[i].clear();
    }
    for (int i = N; i; i--) {
      if (R[i + 1][s[i]]) {
        int pos = R[i + 1][s[i]] + 1;
        R[i].swap(R[pos]);
        if (pos < N) {
          R[i][s[pos]] = pos;
        }
        dp[i] = dp[pos] + 1;
        ans += dp[i];
      }
      R[i][s[i]] = i;
    }
    if (ans < 2e9)
      printf("%d\n", (int)ans);
    else
      printf("%lld\n", ans);
  }
}
