#include <bits/stdc++.h>
using namespace std;
int id[300010], dp[300010], a[300010], to[300010], cnt;
long long ans;
unordered_map<int, int> s[300010];
int main() {
  int T, n;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) dp[i] = 0, to[i] = -1;
    for (int i = 1; i <= n; i++) s[i].clear(), id[i] = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      to[i] = s[id[i - 1]][a[i]] - 1;
      if (to[i] != -1) id[i] = id[to[i]];
      if (!id[i]) id[i] = ++cnt;
      s[id[i]][a[i]] = i;
    }
    ans = 0;
    for (int i = 1; i <= n; i++) {
      dp[i] = 0;
      if (to[i] != -1) dp[i] = 1 + dp[to[i]], ans += dp[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
