#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 600000;
long long MOD = 1e9 + 7;
long long INF = 1e18;
const int K = 51;
vector<long long> st;
vector<long long> st2;
long long hs(long long a, long long b) {
  return (a * 23101 + 93024) ^ (a << 6) ^ (a >> 6) ^ (b << 6) ^ (b >> 6) ^
         (b * 220203 + 123133123);
}
void add(long long a) {
  if (!st.size() || st.back() != a) {
    st.push_back(a);
    if (st2.size()) {
      st2.push_back(hs(st2.back(), a));
    } else {
      st2.push_back(a);
    }
  } else {
    st.pop_back();
    st2.pop_back();
  }
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(20);
  long long tst;
  cin >> tst;
  while (tst--) {
    st2.clear();
    st.clear();
    st2.push_back(0);
    long long n;
    cin >> n;
    vector<long long> a(n);
    map<long long, long long> cn;
    long long ans = 0;
    cn[0] = 1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      add(a[i]);
      if (cn.count(st2.back())) ans += cn[st2.back()];
      cn[st2.back()]++;
    }
    cout << ans << "\n";
  }
}
