#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 300005;
int power(int b, int exp) {
  int res = 1;
  while (exp > 0) {
    if (exp % 2) {
      res = 1LL * res * b % mod;
    }
    b = 1LL * b * b % mod;
    exp /= 2;
  }
  return res;
}
int a[N], dp[N], nxt[N];
bool was[N];
int main() {
  int test = 1, n;
  scanf("%d", &test);
  while (test--) {
    long long ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      was[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      if (i < n - i + 1) {
        swap(a[i], a[n - i + 1]);
      }
    }
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
      if (!was[a[i]]) {
        was[a[i]] = 1;
        nxt[i] = 0;
        dp[i] = 0;
        continue;
      }
      nxt[i] = i - 1;
      while (nxt[i] > 0 && a[i] != a[nxt[i]]) {
        nxt[i] = nxt[nxt[i]] - 1;
      }
      if (nxt[i] > 0) {
        dp[i] = 1 + dp[nxt[i] - 1];
        ans += dp[i];
      } else {
        nxt[i] = 0;
        dp[i] = 0;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
