#include <bits/stdc++.h>
using namespace std;
const long long dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const long long dir2[8][2] = {{1, 1},  {1, 0},  {1, -1}, {0, 1},
                              {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}};
long long n;
long long a[300005];
long long to[300005];
long long belong[300005];
map<long long, long long> to2[300005];
long long cnt = 0;
long long ans = 0;
void ini() {
  long long i;
  ans = 0;
  for (i = 0; i <= n + 3; i++) {
    to[i] = 0;
    to2[i].clear();
    belong[i] = 0;
  }
  cnt = 0;
}
void wk() {
  long long i, j;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
  ini();
  for (i = n; i >= 1; i--) {
    long long f = to2[belong[i + 1]][a[i]];
    if (f != 0) {
      to[i] = f;
      belong[i] = belong[f + 1];
    } else {
      belong[i] = ++cnt;
    }
    to2[belong[i]][a[i]] = i;
  }
  for (i = 1; i <= n; i++) {
    long long cnt = 0;
    if (to[i] != 0) {
      for (j = i; j <= n;) {
        long long f = to[j] + 1;
        cnt++;
        to[j] = 0;
        if (f > n || to[f] == 0) break;
        j = f;
      }
    }
    ans += (1 + cnt) * cnt / 2;
  }
  printf("%lld\n", ans);
}
int main() {
  long long q;
  long long i;
  cin >> q;
  for (i = 1; i <= q; i++) wk();
  return 0;
}
