#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int arr[300009], ans[300009], par[300009];
map<int, int> dp[300009];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", arr + i);
    for (int i = n - 1; i >= 1; i--) {
      if (arr[i] == arr[i + 1])
        par[i] = i + 1;
      else if (par[i + 1])
        par[i] = dp[i + 1][arr[i]];
      if (par[i]) {
        swap(dp[i], dp[par[i] + 1]);
        dp[i][arr[par[i] + 1]] = par[i] + 1;
      }
    }
    long long res = 0;
    for (int i = n; i >= 1; i--)
      if (par[i]) {
        ans[i] = ans[par[i] + 1] + 1;
        res += ans[i];
      }
    printf("%lld\n", res);
    for (int i = 1; i <= n + 3; i++) {
      arr[i] = ans[i] = par[i] = 0;
      dp[i].clear();
    }
  }
  return 0;
}
