#include <bits/stdc++.h>
using namespace std;
long long inp, Inp;
long long i1, i2, i3, i4, i5, i6, i7, i8;
long long MOD = 998244353, MOD1 = (long long)1e9 + 7, MOD2 = (long long)1e9 + 9;
long long MOD3 = (long long)1e9 + 21;
double eps = 1e-9;
long long TMP =
    (chrono::high_resolution_clock::now().time_since_epoch().count() % MOD +
     MOD) %
    MOD;
auto STTMP = chrono::steady_clock::now();
struct SegTree {
  int n;
  int t[2 * (long long)(1e6 + 2)];
  void build() {
    for (int i = n - 1; i > 0; --i) t[i] = t[i << 1] + t[i << 1 | 1];
  }
  void modifyp(int p, int value) {
    for (t[p += n] += value; p > 1; p >>= 1) t[p >> 1] = t[p] + t[p ^ 1];
  }
  int querylr(int l, int r) {
    int res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res += t[l++];
      if (r & 1) res += t[--r];
    }
    return res;
  }
};
bool ccomp(pair<long long, long long> l, pair<long long, long long> r) {
  return l.second - l.first > r.second - r.first;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  std::cout.precision(20);
  srand((unsigned int)TMP);
  long long T;
  cin >> T;
  for (int t = (0); t < (T); t++) {
    long long N;
    cin >> N;
    vector<long long> A;
    for (int i = (0); i < (N); i++) {
      cin >> i1;
      A.push_back(i1);
    }
    vector<pair<long long, long long>> seg;
    for (int i = (0); i < (N); i++) {
      for (int j = (i + 1); j < (N); j++) {
        if (A.at(i) == A.at(j)) {
          seg.push_back({i, j});
        }
      }
    }
    sort(seg.begin(), seg.end(), ccomp);
    long long res = 0;
    SegTree st;
    st.n = N;
    for (int i = (N); i < (2 * N); i++) {
      st.t[i] = 0;
    }
    st.build();
    for (int i = (0); i < (seg.size()); i++) {
      res += st.querylr(seg.at(i).first + 1, seg.at(i).second);
      st.modifyp(seg.at(i).first, 1);
      st.modifyp(seg.at(i).second, 1);
    }
    cout << res << "\n";
  }
  return 0;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

You are given an array a_1, a_2 ... a_n. Calculate the number of tuples (i, j, k, l) such that: 

  * 1 ≤ i < j < k < l ≤ n; 
  * a_i = a_k and a_j = a_l; 

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.

The first line of each test case contains a single integer n (4 ≤ n ≤ 3000) — the size of the array a.

The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the array a.

It's guaranteed that the sum of n in one test doesn't exceed 3000.

Output

For each test case, print the number of described tuples.

Example

Input


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


Output


5
2

Note

In the first test case, for any four indices i < j < k < l are valid, so the answer is the number of tuples.

In the second test case, there are 2 valid tuples: 

  * (1, 2, 4, 6): a_1 = a_4 and a_2 = a_6; 
  * (1, 3, 4, 6): a_1 = a_4 and a_3 = a_6. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long inp, Inp;
long long i1, i2, i3, i4, i5, i6, i7, i8;
long long MOD = 998244353, MOD1 = (long long)1e9 + 7, MOD2 = (long long)1e9 + 9;
long long MOD3 = (long long)1e9 + 21;
double eps = 1e-9;
long long TMP =
    (chrono::high_resolution_clock::now().time_since_epoch().count() % MOD +
     MOD) %
    MOD;
auto STTMP = chrono::steady_clock::now();
struct SegTree {
  int n;
  int t[2 * (long long)(1e6 + 2)];
  void build() {
    for (int i = n - 1; i > 0; --i) t[i] = t[i << 1] + t[i << 1 | 1];
  }
  void modifyp(int p, int value) {
    for (t[p += n] += value; p > 1; p >>= 1) t[p >> 1] = t[p] + t[p ^ 1];
  }
  int querylr(int l, int r) {
    int res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res += t[l++];
      if (r & 1) res += t[--r];
    }
    return res;
  }
};
bool ccomp(pair<long long, long long> l, pair<long long, long long> r) {
  return l.second - l.first > r.second - r.first;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  std::cout.precision(20);
  srand((unsigned int)TMP);
  long long T;
  cin >> T;
  for (int t = (0); t < (T); t++) {
    long long N;
    cin >> N;
    vector<long long> A;
    for (int i = (0); i < (N); i++) {
      cin >> i1;
      A.push_back(i1);
    }
    vector<pair<long long, long long>> seg;
    for (int i = (0); i < (N); i++) {
      for (int j = (i + 1); j < (N); j++) {
        if (A.at(i) == A.at(j)) {
          seg.push_back({i, j});
        }
      }
    }
    sort(seg.begin(), seg.end(), ccomp);
    long long res = 0;
    SegTree st;
    st.n = N;
    for (int i = (N); i < (2 * N); i++) {
      st.t[i] = 0;
    }
    st.build();
    for (int i = (0); i < (seg.size()); i++) {
      res += st.querylr(seg.at(i).first + 1, seg.at(i).second);
      st.modifyp(seg.at(i).first, 1);
      st.modifyp(seg.at(i).second, 1);
    }
    cout << res << "\n";
  }
  return 0;
}

```