#include <bits/stdc++.h>
using namespace std;
int q, n, a[300005];
map<pair<int, int>, int> mp;
int t, st[300005], hsh1[300005], hsh2[300005];
void go() { mp[pair<int, int>(hsh1[t - 1], hsh2[t - 1])]++; }
int main() {
  scanf("%d", &q);
  while (q--) {
    hsh1[0] = hsh2[0] = 0;
    t = 1;
    mp.clear();
    mp[pair<int, int>(0, 0)]++;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      if (t > 1 && st[t - 1] == a[i])
        t--;
      else {
        hsh1[t] = (1LL * 19260817 * hsh1[t - 1] + a[i]) % 1000000007;
        hsh2[t] = (1LL * 19991020 * hsh2[t - 1] + a[i]) % 998244383;
        st[t] = a[i];
        t++;
      }
      go();
    }
    long long ans = 0;
    for (auto p : mp) ans += 1LL * (p.second) * (p.second - 1) / 2;
    printf("%lld\n", ans);
  }
  return 0;
}
