#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int q, n, a[N], pos[N], dp[N], pre[N];
long long ans = 0;
int main() {
  scanf("%d", &q);
  while (q--) {
    ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) pre[i] = -1;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      dp[i] = 0;
      pos[i] = N;
      if (pre[a[i]] == -1) {
        pre[a[i]] = i;
      }
    }
    dp[N - 1] = 0;
    for (int i = 0; i < n; i++) {
      if (a[i + 1] == a[i])
        pos[i + 1] = i;
      else {
        if (a[i + 1] == a[pos[i] - 1]) {
          pos[i + 1] = pos[i] - 1;
          continue;
        }
        int tmp = i;
        while (a[i + 1] != a[pos[tmp] - 1]) {
          tmp = pos[tmp] - 1;
          if (a[i + 1] == a[pos[tmp] - 1]) {
            pos[i + 1] = pos[tmp] - 1;
            break;
          }
          if (tmp == N - 1 || tmp < pre[a[i + 1]]) {
            pos[i + 1] = N;
            break;
          }
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (pos[i] != N) dp[i] = 1;
    }
    for (int i = 0; i < n; i++) {
      dp[i] += dp[pos[i] - 1];
      ans += dp[i];
    }
    printf("%lld\n", ans);
  }
}
