#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long MOD = 1e9 + 7, p = 1276351;
long long ans = 0;
const long long N = 3e5 + 100;
long long a[N];
long long p1[N + 1];
unsigned long long p2[N + 1];
long long n;
pair<long long, unsigned long long> operator+(
    pair<long long, unsigned long long> a,
    pair<long long, unsigned long long> b) {
  return make_pair((a.first + b.first) % MOD, a.second + b.second);
}
pair<long long, unsigned long long> operator-(
    pair<long long, unsigned long long> a,
    pair<long long, unsigned long long> b) {
  return make_pair((a.first - b.first + MOD) % MOD, a.second - b.second);
}
pair<long long, unsigned long long> operator*(
    pair<long long, unsigned long long> a, long long x) {
  return make_pair(a.first * p1[x] % MOD, a.second * p2[x]);
}
void stupid(long long l, long long r) {
  for (long long i = l; i <= r; i++) {
    vector<long long> cur;
    for (long long j = i; j <= r; j++) {
      if ((long long)cur.size() && cur.back() == a[j]) {
        cur.pop_back();
        if ((long long)cur.size() == 0) ans++;
      } else
        cur.push_back(a[j]);
    }
  }
}
void rec(long long l, long long r) {
  if (r - l < 2) {
    stupid(l, r);
    return;
  }
  long long mid = (l + r) / 2;
  map<pair<long long, unsigned long long>, long long> cnt;
  vector<long long> cur;
  pair<long long, unsigned long long> h = {0, 0};
  auto get = [&](long long pos, long long x) {
    return make_pair(p1[pos] * x % MOD, p2[pos] * x);
  };
  for (long long i = mid + 1; i <= r; i++) {
    if ((long long)cur.size() && cur.back() == a[i]) {
      h = h - get((long long)cur.size() - 1, cur.back());
      cur.pop_back();
    } else {
      h = h + get((long long)cur.size(), a[i]);
      cur.push_back(a[i]);
    }
    cnt[h]++;
  }
  h = {0, 0};
  cur.clear();
  for (long long i = mid; i >= l; i--) {
    if ((long long)cur.size() && cur.back() == a[i]) {
      h = h - get((long long)cur.size() - 1, cur.back());
      cur.pop_back();
    } else {
      h = h + get((long long)cur.size(), a[i]);
      cur.push_back(a[i]);
    }
    ans += cnt[h];
  }
  rec(l, mid);
  rec(mid + 1, r);
}
void solve() {
  cin >> n;
  ans = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  rec(0, n - 1);
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  p1[0] = p2[0] = 1;
  for (long long i = 0; i < N; i++) {
    p1[i + 1] = p1[i] * p % MOD;
    p2[i + 1] = p2[i] * p;
  }
  long long q;
  cin >> q;
  while (q--) {
    solve();
  }
}
