#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char c = getchar();
  long long x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
long long n, qaqaqa, a[500005], nxt[500005];
long long f[500005], res;
map<long long, long long> mp[500005];
long long nowclk;
void work() {
  n = read(), res = 0;
  f[n + 1] = 0, nxt[n + 1] = -1, mp[n + 1].clear();
  for (register long long i = (1); i <= (n); ++i)
    a[i] = read(), f[i] = 0, nxt[i] = -1, mp[i].clear();
  for (register long long i = (n); i >= (1); --i) {
    if (mp[i + 1].count(a[i])) {
      nxt[i] = mp[i + 1][a[i]];
      swap(mp[i], mp[nxt[i] + 1]);
      if (nxt[i] < n) mp[i][a[nxt[i] + 1]] = nxt[i] + 1;
    }
    mp[i][a[i]] = i;
  }
  f[n + 1] = 0;
  for (register long long i = (n); i >= (1); --i) {
    if (nxt[i] != -1) f[i] = f[nxt[i] + 1] + 1, res += f[i];
  }
  cout << res << endl;
}
signed main() {
  long long T = read();
  while (T--) work();
  return 0;
}
