#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int num = 0; num < q; num++) {
    int n;
    cin >> n;
    map<int, map<int, int>> nxtX;
    vector<int> a(n);
    vector<int> nxt(n + 1, -1), dp(n + 1, 0);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = n - 1; i > -1; i--) {
      if (nxtX[i + 1].find(a[i]) != nxtX[i + 1].end()) {
        int pos = nxtX[i + 1][a[i]];
        nxt[i] = pos;
        swap(nxtX[i], nxtX[pos + 1]);
        if (pos < n - 1) nxtX[i][a[pos + 1]] = pos + 1;
      }
      nxtX[i][a[i]] = i;
    }
    long long res = 0;
    for (int i = n - 1; i > -1; i--) {
      if (nxt[i] != -1) {
        dp[i] = 1 + dp[nxt[i] + 1];
        res += dp[i];
      }
    }
    cout << res << endl;
  }
}
