#include <bits/stdc++.h>
long long read() {
  long long f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
bool umax(long long& a, long long b) {
  if (b > a) return a = b, 1;
  return 0;
}
bool umin(long long& a, long long b) {
  if (b < a) return a = b, 1;
  return 0;
}
long long a[500011], f[500011], nxt[500011];
std::map<long long, long long> p[500011];
int main() {
  long long task = read();
  while (task--) {
    long long n = read(), ans = 0;
    for (long long i = 1; i <= n; ++i) a[i] = read();
    for (long long i = 0; i <= n; ++i) p[i].clear(), nxt[i] = 0, f[i] = 0;
    for (long long i = 1; i <= n; ++i) {
      if (p[i - 1][a[i]]) {
        long long pos = p[i - 1][a[i]];
        f[i] = f[pos - 1] + 1;
        ans += f[i];
        std::swap(p[i], p[pos - 1]);
        if (pos > 1) p[i][a[pos - 1]] = pos - 1;
      }
      p[i][a[i]] = i;
    }
    printf("%lld\n", ans);
  }
}
