#include <bits/stdc++.h>
using std::abs;
using std::array;
using std::cerr;
using std::cin;
using std::cout;
using std::generate;
using std::get;
using std::make_pair;
using std::make_tuple;
using std::map;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::pair;
using std::queue;
using std::reverse;
using std::set;
using std::sort;
using std::string;
using std::swap;
using std::tuple;
using std::unique;
using std::vector;
template <typename T>
T input() {
  T res;
  cin >> res;
  {};
  return res;
}
template <typename IT>
void input_seq(IT b, IT e) {
  std::generate(b, e,
                input<typename std::remove_reference<decltype(*b)>::type>);
}
int main() {
  std::iostream::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  for (int q = input<int>(); q != 0; --q) {
    int n = input<int>();
    vector<int> a(n);
    input_seq(a.begin(), a.end());
    const int inf = 2 * n;
    vector<int> nxt(n, inf);
    vector<map<int, int>> mps(n);
    mps[n - 1][a[n - 1]] = n - 1;
    for (int i = n - 2; i >= 0; --i) {
      if (mps[i + 1].count(a[i])) nxt[i] = mps[i + 1][a[i]];
      if (nxt[i] != inf and nxt[i] != n - 1) {
        mps[i] = std::move(mps[nxt[i] + 1]);
      }
      mps[i][a[i]] = i;
    }
    vector<int> len(n + 3, 0);
    for (int i = n - 1; i >= 0; --i)
      if (nxt[i] != inf) len[i] = 1 + len[nxt[i] + 1];
    cout << std::accumulate(len.begin(), len.end(), int64_t(0)) << "\n";
  }
  return 0;
}
