#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 100;
long long a[N], go[N], dp[N];
map<long long, long long> mp[N];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mp[i].clear();
  }
  long long d = 0;
  for (long long i = 0; i < n; i++) {
    dp[i] = 0;
    go[i] = -1;
    if (i && a[i] == a[i - 1])
      go[i] = i - 1;
    else if (i && mp[i - 1].count(a[i]))
      go[i] = mp[i - 1][a[i]];
    if (go[i] > 0) mp[go[i] - 1].swap(mp[i]);
    mp[i][a[i]] = i;
    if (~go[i]) dp[i] = 1 + (go[i] ? dp[go[i] - 1] : 0);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) ans += dp[i];
  cout << ans << "\n";
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
}
