#include <bits/stdc++.h>
using namespace std;
class trio {
 public:
  long long first, second, third;
};
int32_t main() {
  long long third;
  scanf("%lld", &third);
  while (third--) {
    long long n;
    scanf("%lld", &n);
    long long arr[n + 1];
    arr[0] = 0;
    for (long long i = 1; i < n + 1; ++i) scanf("%lld", &arr[i]);
    map<long long, long long> back[n + 1];
    long long dp[n + 1];
    memset(dp, 0, sizeof(dp));
    long long ans = 0;
    for (long long i = 1; i < n + 1; ++i) {
      if (arr[i] == arr[i - 1]) {
        long long ind = i - 1;
        dp[i] = dp[ind - 1] + 1;
        ans += dp[i];
        swap(back[i], back[ind - 1]);
        back[i][arr[ind - 1]] = ind - 1;
      } else {
        if (back[i - 1].find(arr[i]) != back[i - 1].end()) {
          long long ind = back[i - 1][arr[i]];
          dp[i] = dp[ind - 1] + 1;
          ans += dp[i];
          swap(back[i], back[ind - 1]);
          back[i][arr[ind - 1]] = ind - 1;
        }
      }
    }
    printf("%lld ", ans);
    printf("\n");
  }
  return 0;
}
