#include <bits/stdc++.h>
using namespace std;
long long q, n;
long long a[1100000], f[1100000], nxt[1100000];
map<long long, long long> p[1100000];
signed main() {
  cin >> q;
  while (q--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (long long i = 1; i <= n + 1; i++) p[i].clear(), f[i] = 0, nxt[i] = -1;
    for (long long i = n; i; i--) {
      if (p[i + 1].count(a[i])) {
        long long x = p[i + 1][a[i]];
        nxt[i] = x;
        swap(p[i], p[x + 1]);
        if (x < n) p[i][a[x + 1]] = x + 1;
      }
      p[i][a[i]] = i;
    }
    long long r = 0;
    for (long long i = n; i; i--) {
      if (nxt[i] == -1) continue;
      f[i] = f[nxt[i] + 1] + 1;
      r += f[i];
    }
    printf("%lld\n", r);
  }
  return 0;
}
