#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1000000000;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
struct IOSetup {
  IOSetup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(12);
  }
} iosetup;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
  return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v) is >> x;
  return is;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  vector<ll> dp(n + 1, 0);
  vector<map<int, ll>> nxt(n + 1);
  ll res = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (nxt[i + 1].count(a[i])) {
      int r = nxt[i + 1][a[i]];
      dp[i] = dp[r] + 1;
      res += dp[i];
      nxt[i] = move(nxt[r]);
    }
    nxt[i][a[i]] = i + 1;
  }
  cout << res << "\n";
}
signed main() {
  int q;
  cin >> q;
  while (q--) solve();
  return 0;
}
