Problem: Let's look at the following process: initially you have an empty stack and an array s of the length l. You are trying to push array elements to the stack in the order s_1, s_2, s_3, ... s_{l}. Moreover, if the stack is empty or the element at the top of this stack is not equal to the current element, then you just push the current element to the top of the stack. Otherwise, you don't push the current element to the stack and, moreover, pop the top element of the stack. 

If after this process the stack remains empty, the array s is considered stack exterminable.

There are samples of stack exterminable arrays: 

  * [1, 1]; 
  * [2, 1, 1, 2]; 
  * [1, 1, 2, 2]; 
  * [1, 3, 3, 1, 2, 2]; 
  * [3, 1, 3, 3, 1, 3]; 
  * [3, 3, 3, 3, 3, 3]; 
  * [5, 1, 2, 2, 1, 4, 4, 5]; 



Let's consider the changing of stack more details if s = [5, 1, 2, 2, 1, 4, 4, 5] (the top of stack is highlighted). 

  1. after pushing s_1 = 5 the stack turn into [5]; 
  2. after pushing s_2 = 1 the stack turn into [5, 1]; 
  3. after pushing s_3 = 2 the stack turn into [5, 1, 2]; 
  4. after pushing s_4 = 2 the stack turn into [5, 1]; 
  5. after pushing s_5 = 1 the stack turn into [5]; 
  6. after pushing s_6 = 4 the stack turn into [5, 4]; 
  7. after pushing s_7 = 4 the stack turn into [5]; 
  8. after pushing s_8 = 5 the stack is empty. 



You are given an array a_1, a_2, …, a_n. You have to calculate the number of its subarrays which are stack exterminable.

Note, that you have to answer q independent queries.

Input

The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries.

The first line of each query contains one integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the length of array a.

The second line of each query contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — the elements.

It is guaranteed that the sum of all n over all queries does not exceed 3 ⋅ 10^5.

Output

For each test case print one integer in single line — the number of stack exterminable subarrays of the array a.

Example

Input


3
5
2 1 1 2 2
6
1 2 1 1 3 2
9
3 1 2 2 1 6 6 3 3


Output


4
1
8

Note

In the first query there are four stack exterminable subarrays: a_{1 … 4} = [2, 1, 1, 2], a_{2 … 3} = [1, 1], a_{2 … 5} = [1, 1, 2, 2], a_{4 … 5} = [2, 2].

In the second query, only one subarray is exterminable subarray — a_{3 … 4}.

In the third query, there are eight stack exterminable subarrays: a_{1 … 8}, a_{2 … 5}, a_{2 … 7}, a_{2 … 9}, a_{3 … 4}, a_{6 … 7}, a_{6 … 9}, a_{8 … 9}.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class T, class second>
ostream &operator<<(ostream &s, pair<T, second> &p) {
  s << '{' << p.first << ", " << p.second << '}';
  return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<T> &v) {
  if (v.empty()) {
    s << "[]";
    return s;
  }
  s << '[';
  for (int i = 0; i < v.size() - 1; i++) {
    s << v[i] << ", ";
  }
  s << v.back() << ']';
  return s;
}
static mt19937 random_gen(
    chrono::high_resolution_clock::now().time_since_epoch().count());
int rand() {
  static uniform_int_distribution<int> uid(0, INT32_MAX);
  return uid(random_gen);
}
template <typename T, size_t second>
inline void operator*=(array<T, second> &a, const array<T, second> &b) {
  for (int i = 0; i < second; i++) {
    a[i] *= b[i];
  }
}
template <typename T, size_t second>
inline array<T, second> operator*(const array<T, second> &a,
                                  const array<T, second> &b) {
  array<T, second> res = a;
  res *= b;
  return res;
}
template <typename T, size_t second>
inline array<T, second> operator*(const array<T, second> &a, const int v) {
  array<T, second> res = a;
  for (int i = 0; i < second; i++) {
    res[i] *= v;
  }
  return res;
}
template <typename T, size_t second>
inline void operator%=(array<T, second> &a, const array<T, second> &b) {
  for (int i = 0; i < second; i++) {
    a[i] %= b[i];
  }
}
template <typename T, size_t second>
inline array<T, second> operator%(const array<T, second> &a,
                                  const array<T, second> &b) {
  array<T, second> res = a;
  res %= b;
  return res;
}
template <typename T, size_t second>
inline void operator+=(array<T, second> &a, const array<T, second> &b) {
  for (int i = 0; i < second; i++) {
    a[i] += b[i];
  }
}
template <typename T, size_t second>
inline array<T, second> operator+(const array<T, second> &a,
                                  const array<T, second> &b) {
  array<T, second> res = a;
  res += b;
  return res;
}
template <typename T, size_t second>
inline void operator-=(array<T, second> &a, const array<T, second> &b) {
  for (int i = 0; i < second; i++) {
    a[i] -= b[i];
  }
}
template <typename T, size_t second>
inline array<T, second> operator-(const array<T, second> &a,
                                  const array<T, second> &b) {
  array<T, second> res = a;
  res -= b;
  return res;
}
template <typename T, size_t second>
inline ostream &operator<<(ostream &s, const array<T, second> &a) {
  if (second == 0) {
    s << "[]";
  } else {
    s << '[';
    for (int i = 0; i < second - 1; i++) {
      s << a[i] << ", ";
    }
    s << a[second - 1] << ']';
  }
  return s;
}
int n;
array<int64_t, 24> pws[300005];
const array<int64_t, 24> mlt = {
    4102697LL, 3468533LL, 3904801LL, 4180607LL, 3250627LL, 4082513LL,
    3376343LL, 3665609LL, 3171277LL, 4084391LL, 4113661LL, 3193081LL,
    3938513LL, 3706433LL, 3915239LL, 3443017LL, 3402239LL, 3277777LL,
    4174727LL, 3316267LL, 3905911LL, 3263243LL, 3199171LL, 3503699LL,
};
const array<int64_t, 24> md = {
    866185961LL, 957273517LL,  941679047LL,  820397099LL, 995925493LL,
    917554819LL, 901490153LL,  1015402403LL, 866080513LL, 1032164149LL,
    945956189LL, 818808203LL,  981828797LL,  950823121LL, 1060816553LL,
    881891513LL, 1051800059LL, 937888933LL,  865977481LL, 1042799077LL,
    854373083LL, 1056322507LL, 948902657LL,  907540741LL,
};
array<int64_t, 24> mdi;
inline int64_t modpow(int64_t bs, int64_t pw, const int64_t md) {
  bs %= md;
  int64_t ans = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      ans = (ans * bs) % md;
    }
    bs = (bs * bs) % md;
  }
  return ans;
}
int main() {
  for (int i = 0; i < 24; i++) {
    pws[0][i] = 1;
  }
  for (int i = 1; i < 300005; i++) {
    pws[i] = (pws[i - 1] * mlt) % md;
  }
  for (int i = 0; i < 24; i++) {
    mdi[i] = modpow(mlt[i], md[i] - 2, md[i]);
    assert(((mdi[i] * mlt[i]) % md[i]) == 1);
  }
  for (int _t_, _q_ = 0, __ = scanf("%d", &_t_); _q_ < _t_; _q_++) {
    scanf("%d", &n);
    map<array<int64_t, 24>, int> cnts;
    array<int64_t, 24> curr;
    fill(begin(curr), end(curr), 0);
    cnts[curr] = 1;
    stack<int> stk;
    int64_t ans = 0;
    for (int i = 1; i <= n; i++) {
      int a;
      scanf("%d", &a);
      if (stk.size() && stk.top() == a) {
        curr -= ((pws[stk.size()] * a) % md);
        curr += md;
        stk.pop();
      } else {
        curr += pws[stk.size() + 1] * a;
        stk.push(a);
      }
      curr %= md;
      ans += cnts[curr];
      cnts[curr]++;
    }
    printf("%lld\n", ans);
  }
  return 0;
}