#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
int N;
int A[300011];
int dp[300011];
map<int, int> mp[300011];
void MAIN() {
  scanf("%d", &N);
  for (int i = 0, i_len = (N); i < i_len; ++i) scanf("%d", A + i);
  for (int i = 0, i_len = (N + 1); i < i_len; ++i) mp[i].clear();
  long long ans = 0;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    if (i > 0 && A[i - 1] == A[i]) {
      dp[i + 1] = dp[i - 1] + 1;
      swap(mp[i + 1], mp[i - 1]);
    } else {
      auto it = mp[i].find(A[i]);
      if (it != mp[i].end()) {
        int j = it->second;
        dp[i + 1] = dp[j] + 1;
        swap(mp[i + 1], mp[j]);
      } else {
        dp[i + 1] = 0;
      }
    }
    mp[i + 1][A[i]] = i;
    ans += dp[i + 1];
  }
  printf("%lld\n", ans);
}
int main() {
  int TC = 1;
  scanf("%d", &TC);
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}
