#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 10;
long long a[maxn], nxt[maxn], dp[maxn], n, q;
unordered_map<long long, long long> NXT[maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin >> q;
  while (q--) {
    cin >> n;
    for (long long i = 0; i < n; i++) cin >> a[i];
    nxt[n - 1] = -1;
    for (long long i = n - 2; ~i; i--) {
      if (a[i] == a[i + 1])
        nxt[i] = i + 1;
      else if (NXT[i + 1].count(a[i]))
        nxt[i] = NXT[i + 1][a[i]] + 1;
      else
        nxt[i] = -1;
      if (nxt[i] != -1) {
        if (nxt[i] < n - 1) {
          swap(NXT[i], NXT[nxt[i] + 1]);
          NXT[i][a[nxt[i] + 1]] = nxt[i];
        }
        dp[i] += dp[nxt[i] + 1] + 1;
      }
    }
    for (long long i = n - 2; ~i; i--) dp[i] += dp[i + 1];
    cout << dp[0] << '\n';
    for (long long i = 0; i <= n; i++) NXT[i].clear(), dp[i] = 0;
  }
  return 0;
}
