#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000 + 20;
const int INF = 1000000000;
int nxt[MAXN], arr[MAXN], n;
long long d[MAXN];
map<int, int> mp[MAXN];
int main() {
  int _;
  cin >> _;
  while (_--) {
    scanf("%d", &n);
    for (int i = 0; i <= n; ++i) mp[i].clear();
    memset(nxt, -1, sizeof(int) * (n + 1));
    memset(d, 0, sizeof(long long) * (n + 1));
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &arr[i]);
      if (mp[i - 1].count(arr[i])) {
        int idx = mp[i - 1][arr[i]];
        nxt[i] = idx - 1;
        swap(mp[i], mp[idx - 1]);
      }
      mp[i][arr[i]] = i;
      if (nxt[i] == -1) continue;
      d[i] = d[nxt[i]] + 1;
      ans += d[i];
    }
    cout << ans << endl;
  }
}
