#include <bits/stdc++.h>
using namespace std;
const int N = 300001;
map<int, int> g[N];
int dep[N];
int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) g[i].clear();
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
      int a;
      scanf("%d", &a);
      auto it = g[i - 1].find(a);
      if (it == g[i - 1].end()) {
        g[i][a] = i;
        dep[i] = 0;
      } else {
        int r = it->second;
        g[i] = move(g[r - 1]);
        g[i][a] = i;
        dep[i] = dep[r - 1] + 1;
        ans += dep[i];
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
