#include <bits/stdc++.h>
using namespace std;
const int mxn = 300001;
int n;
long long a[mxn], dp[mxn];
map<int, int> first[mxn];
void answer() {
  cin >> n;
  long long ret = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    first[i].clear();
    if (first[i - 1].count(a[i])) {
      int x = first[i - 1][a[i]];
      ret += (dp[i] = (x ? dp[x - 1] : 0) + 1);
      swap(first[i], first[x - 1]);
      first[i][a[x - 1]] = x - 1;
    } else {
      dp[i] = 0;
    }
    first[i][a[i]] = i;
  }
  cout << ret << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) answer();
  return 0;
}
