#include <bits/stdc++.h>
using namespace std;
template <typename T = int>
T input() {
  T res;
  cin >> res;
  return res;
}
template <typename It>
void input_seq(It begin, It end, istream &in = cin) {
  generate(begin, end,
           input<typename remove_reference<decltype(*begin)>::type>);
}
template <class It>
void output(It begin, It end, ostream &out = cerr) {
  while (begin != end) {
    out << *(begin++) << ' ';
  }
  out << endl;
}
const int N = 3e5 + 47;
unsigned long long a[N], h[N], g[N];
unsigned long long go(int l, int r) {
  if (l == r) {
    return 0;
  }
  int m = (l + r) / 2;
  unsigned long long ans = 0;
  ans += go(l, m);
  ans += go(m + 1, r);
  map<unsigned long long, int> le, ri;
  unsigned long long le_hash = 0, ri_hash = 0;
  vector<int> le_st, ri_st;
  for (int j = m; j >= l; --j) {
    if ((int)le_st.size() && le_st.back() == a[j]) {
      le_st.pop_back();
      le_hash -= g[(int)le_st.size()] * h[a[j]];
    } else {
      le_hash += g[(int)le_st.size()] * h[a[j]];
      le_st.emplace_back(a[j]);
    }
    ++le[le_hash];
  }
  for (int j = m + 1; j <= r; ++j) {
    if ((int)ri_st.size() && ri_st.back() == a[j]) {
      ri_st.pop_back();
      ri_hash -= g[(int)ri_st.size()] * h[a[j]];
    } else {
      ri_hash += g[(int)ri_st.size()] * h[a[j]];
      ri_st.emplace_back(a[j]);
    }
    ++ri[ri_hash];
  }
  for (auto [hash, cnt_left] : le) {
    ans += 1ull * cnt_left * ri[hash];
  }
  return ans;
}
void solve() {
  static mt19937_64 rnd(
      chrono::high_resolution_clock::now().time_since_epoch().count());
  int n = input();
  for (int i = 0; i < n; ++i) {
    a[i] = input() - 1;
    h[i] = rnd();
    g[i] = rnd();
  }
  cout << go(0, n - 1) << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int q = input();
  while (q--) {
    solve();
  }
}
