#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n, arr[N], nxt[N];
long long dp[N], ans = 0;
int comp[N], comp_cnt = 0;
set<pair<int, int> > st[N];
set<pair<int, int> >::iterator it;
void solve() {
  scanf("%d", &n);
  comp_cnt = 0;
  for (int i = 0; i < n; i++) {
    st[i].clear();
    scanf("%d", &arr[i]);
    dp[i] = 0;
  }
  nxt[n - 1] = -1;
  for (int i = n - 2; i >= 0; i--) {
    nxt[i] = -1;
    if (arr[i + 1] == arr[i]) {
      nxt[i] = i + 1;
    } else if (nxt[i + 1] != -1) {
      it = st[comp[i + 1]].lower_bound(make_pair(arr[i], 0));
      if (it != st[comp[i + 1]].end() && it->first == arr[i]) {
        nxt[i] = it->second;
      }
    }
    if (nxt[i] != -1) {
      if (nxt[i] == n - 1 || nxt[nxt[i] + 1] == -1) {
        comp[i] = comp_cnt++;
        if (nxt[i] != n - 1)
          st[comp[i]].insert(make_pair(arr[nxt[i] + 1], nxt[i] + 1));
      } else {
        comp[i] = comp[nxt[i] + 1];
      }
      it = st[comp[i]].lower_bound(make_pair(arr[i], 0));
      if (it != st[comp[i]].end() && it->first == arr[i]) {
        st[comp[i]].erase(it);
      }
      st[comp[i]].insert(make_pair(arr[i], i));
    }
  }
  dp[n] = 0;
  ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (nxt[i] != -1) {
      dp[i] = 1 + dp[nxt[i] + 1];
      ans += dp[i];
    }
  }
  printf("%lld\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
