#include <bits/stdc++.h>
using i64 = long long;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int n;
    scanf("%d", &n);
    std::vector<int> a(n);
    for (auto &e : a) scanf("%d", &e);
    a.push_back(0);
    std::vector<int> next(n, -1);
    std::vector<std::map<int, int>> aux(n + 1);
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] == a[i + 1]) {
        next[i] = i + 1;
      } else if (auto it = aux[i + 1].find(a[i]); it != aux[i + 1].end()) {
        next[i] = it->second;
      }
      if (next[i] > 0) {
        aux[i] = std::move(aux[next[i] + 1]);
        aux[i][a[next[i] + 1]] = next[i] + 1;
      }
    }
    i64 ret = 0;
    std::vector<i64> cnt(n + 1);
    for (int i = n - 1; i >= 0; i--) {
      if (next[i] < 0) continue;
      cnt[i] = 1 + cnt[next[i] + 1];
      ret += cnt[i];
    }
    printf("%lld\n", ret);
  }
  return 0;
}
