#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 3e5 + 15;
mt19937_64 gen(time(0));
long long h0[N], h1[N];
vector<int> a;
long long res = 0;
void solve(int l, int r) {
  if (r - l <= 1) return;
  int m = (l + r) / 2;
  solve(l, m);
  solve(m, r);
  unordered_map<long long, int> cnt;
  long long h = 0;
  vector<int> st;
  for (int i = m; i < r; i++) {
    if (st.empty() || st.back() != a[i]) {
      st.push_back(a[i]);
      h += h0[(long long)st.size()] * h1[a[i]];
    } else {
      h -= h0[(long long)st.size()] * h1[st.back()];
      st.pop_back();
    }
    cnt[h]++;
  }
  h = 0;
  st.clear();
  for (int i = m - 1; i >= l; i--) {
    if (st.empty() || st.back() != a[i]) {
      st.push_back(a[i]);
      h += h0[(long long)st.size()] * h1[a[i]];
    } else {
      h -= h0[(long long)st.size()] * h1[st.back()];
      st.pop_back();
    }
    res += cnt[h];
  }
}
void run() {
  for (int i = 0; i < N; i++) {
    h0[i] = gen();
    h1[i] = gen();
  }
  int q;
  cin >> q;
  while (q--) {
    res = 0;
    int n;
    cin >> n;
    a.resize(n);
    for (int &first : a) cin >> first;
    solve(0, n);
    cout << res << '\n';
  }
}
signed main() {
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
  ios::sync_with_stdio(0);
  cin.tie(0);
  run();
}
