#include <bits/stdc++.h>
using namespace std;
int T, n, a[300005], nxt[300005];
map<int, int> mp[300005];
int dp[300005];
long long ans;
int main() {
  scanf("%d", &T);
  while (T--) {
    ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 0; i <= n + 1; ++i) mp[i].clear();
    for (int i = 1; i <= n; ++i) nxt[i] = -1;
    for (int i = n; i >= 1; --i) {
      if (mp[i + 1].count(a[i])) {
        int pos = mp[i + 1][a[i]];
        nxt[i] = pos;
        swap(mp[i], mp[pos + 1]);
      }
      mp[i][a[i]] = i;
    }
    dp[n + 1] = 0;
    for (int i = n; i >= 1; --i) {
      dp[i] = 0;
      if (nxt[i] == -1) continue;
      dp[i] = dp[nxt[i] + 1] + 1;
      ans += dp[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
