#include <bits/stdc++.h>
using namespace std;
int a[300300];
int nxt[300300], dep[300300];
int id[300300], flag[300300], mn[191][300300];
int main() {
  int T, n;
  for (cin >> T; T--;) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    long long ans = 0;
    int m = max(1, n / 60);
    dep[n + 1] = 0;
    for (int i = 1; i <= n; i++) flag[i] = 0;
    int cnt = 0;
    for (int i = n; i >= 1; i--) {
      int j = i + 1;
      while (j <= n && a[j] != a[i]) {
        if (flag[j]) {
          j = mn[flag[j]][a[i]];
          break;
        }
        j = nxt[j] + 1;
      }
      if (j > n) {
        nxt[i] = n + 1;
        dep[i] = 0;
      } else {
        nxt[i] = j;
        dep[i] = dep[j + 1] + 1;
      }
      ans += dep[i];
      if (i % m == m - 1 || i % m == 0 || i % m == 1) {
        flag[i] = ++cnt;
        for (int j = 1; j <= n; j++) mn[cnt][j] = n + 1;
        int j = i;
        while (j <= n) {
          mn[cnt][a[j]] = min(mn[cnt][a[j]], j);
          j = nxt[j] + 1;
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
