#include <bits/stdc++.h>
using namespace std;
long long n, q, ar[300005], dp[300005];
unordered_map<long long, long long> mr[300005];
int main() {
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> ar[i];
    long long ans = 0;
    for (int i = n - 2; i >= 0; i--) {
      if (ar[i] == ar[i + 1]) {
        swap(mr[i + 2], mr[i]);
        mr[i][ar[i + 2]] = i + 2;
        dp[i] = 1 + dp[i + 2];
      } else {
        if (mr[i + 1].find(ar[i]) == mr[i + 1].end()) {
          continue;
        } else {
          long long pos = mr[i + 1][ar[i]];
          dp[i] = 1 + dp[pos + 1];
          swap(mr[i], mr[pos + 1]);
          mr[i][ar[pos + 1]] = pos + 1;
        }
      }
      ans += dp[i];
    }
    for (int i = 0; i < n + 2; i++) mr[i].clear(), ar[i] = 0, dp[i] = 0;
    cout << ans << "\n";
  }
}
