#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
  os << '(' << a.first << ',' << a.second << ')';
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto x : v) os << x << ' ';
  return os;
}
void debug() { cerr << '\n'; }
template <typename H, typename... T>
void debug(H a, T... b) {
  cerr << a;
  if (sizeof...(b)) cerr << ", ";
  debug(b...);
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<map<int, int>> next(n + 1);
  vector<ll> cnt(n + 1);
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int l = n - 1; l >= 0; l--) {
    int r = -1;
    if (next[l + 1].count(a[l])) {
      r = next[l + 1][a[l]] + 1;
      cnt[l] = cnt[r] + 1;
      ans += cnt[l];
      swap(next[l], next[r]);
    }
    next[l][a[l]] = l;
  }
  cout << ans << "\n";
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
}
