#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const long long N = 300 * 1000 + 228;
long long a[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    a[n + 1] = a[n + 2] = 0;
    vector<unordered_map<long long, long long> > nxtx(n + 5);
    vector<long long> nxt(n + 5);
    nxtx[n][a[n]] = n;
    for (long long i = n - 1; i; --i) {
      if (a[i] == a[i + 1]) {
        nxt[i] = i + 1;
      } else {
        nxt[i] = nxtx[i + 1][a[i]];
      }
      if (nxt[i]) {
        swap(nxtx[i], nxtx[nxt[i] + 1]);
        nxtx[i][a[nxt[i] + 1]] = nxt[i] + 1;
      }
      nxtx[i][a[i]] = i;
    }
    vector<long long> cnt(n + 10);
    long long res = 0;
    for (long long i = n - 1; i; --i) {
      if (nxt[i]) {
        if (nxt[i] > n) {
          exit(-1);
        }
        cnt[i] = cnt[nxt[i] + 1] + 1;
        res += cnt[i];
      }
    }
    cout << res << '\n';
  }
  return 0;
}
