#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 3e5 + 5;
int q, n, s[N], maks[N], dp[N];
map<int, int> mapa[N];
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
    for (int i = 0; i < n; i++) {
      maks[i] = -1;
      mapa[i].clear();
      dp[i] = 0;
    }
    mapa[0][s[0]] = 0;
    for (int i = 1; i < n; i++) {
      if (mapa[i - 1].count(s[i])) {
        int pos = mapa[i - 1][s[i]];
        maks[i] = pos;
        swap(mapa[i], mapa[pos - 1]);
        if (pos > 0) mapa[i][s[pos - 1]] = pos - 1;
      }
      mapa[i][s[i]] = i;
    }
    long long ans = 0;
    for (int i = 1; i < n; i++) {
      if (maks[i] == -1)
        dp[i] = 0;
      else if (maks[i] == 0)
        dp[i] = 1;
      else
        dp[i] = 1 + dp[maks[i] - 1];
      ans += dp[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
