#include <bits/stdc++.h>
using namespace std;
long long q, n;
long long arr[300000 + 5];
long long num[300000 + 5];
long long hsh[300000 + 5];
map<long long, long long> appr;
long long DQ(long long l, long long r) {
  if (l == r) return 0;
  long long mid = (l + r) / 2, now = 1, tmp = 0;
  long long cnt = DQ(l, mid) + DQ(mid + 1, r);
  appr.clear();
  hsh[1] = 0;
  for (long long i = mid; i >= l; i--) {
    if (num[now - 1] == arr[i]) {
      now--;
      appr[hsh[now]]++;
    } else {
      num[now] = arr[i];
      now++;
      hsh[now] =
          now ? (hsh[now - 1] * 300009 + arr[i]) % 4398042316799 : arr[i];
      appr[hsh[now]]++;
    }
  }
  now = 1;
  for (long long i = mid + 1; i <= r; i++) {
    if (num[now - 1] == arr[i]) {
      now--;
      tmp += appr[hsh[now]];
    } else {
      num[now] = arr[i];
      now++;
      hsh[now] =
          now ? (hsh[now - 1] * 300009 + arr[i]) % 4398042316799 : arr[i];
      tmp += appr[hsh[now]];
    }
  }
  return tmp + cnt;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> n;
    for (long long j = 1; j <= n; j++) {
      cin >> arr[j];
    }
    cout << DQ(1, n) << "\n";
  }
  return 0;
}
