#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int a[maxn], N;
int f[maxn], nxt[maxn];
map<int, int> nxtA[maxn];
void solve(void) {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
    nxt[i] = -1;
    f[i] = 0;
    nxtA[i].clear();
  }
  nxtA[N + 1].clear();
  f[N + 1] = 0;
  for (int i = N; i >= 1; --i) {
    if (nxtA[i + 1].count(a[i])) {
      int pos = nxtA[i + 1][a[i]];
      nxt[i] = pos;
      swap(nxtA[i], nxtA[pos + 1]);
      if (pos < N) nxtA[i][a[pos + 1]] = pos + 1;
    }
    nxtA[i][a[i]] = i;
  }
  long long ret = 0;
  for (int i = N; i >= 1; --i) {
    if (nxt[i] == -1) continue;
    f[i] = f[nxt[i] + 1] + 1;
    ret += f[i];
  }
  cout << ret << '\n';
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("A.INP", "r")) {
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  int tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
}
