#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
const long long INF = numeric_limits<long long>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926535898;
const long long LIM = 100005;
long long fpow(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = fpow(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void sieve(long long n) {
  bool prime[5 * LIM];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++)
    if (prime[p] == true)
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
  prime[1] = 0;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
map<long long, long long> primeFactors(long long n) {
  map<long long, long long> mp;
  while (n % 2 == 0) {
    if (mp.count(2) == 1)
      mp[2]++;
    else
      mp.insert({2, 1});
    n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      if (mp.count(i) == 1)
        mp[i]++;
      else
        mp.insert({i, 1});
      n = n / i;
    }
  }
  if (n > 2) {
    if (mp.count(n) == 1)
      mp[n]++;
    else
      mp.insert({n, 1});
  }
  return mp;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  for (long long tt = 1; tt <= t; ++tt) {
    long long n, ans = 0;
    cin >> n;
    vector<long long> a(n);
    for (auto &x : a) cin >> x;
    ;
    vector<long long> mp(n * n + n + 1, 0);
    for (long long i = n - 3; i >= 1; i--) {
      for (long long j = i + 2; j < n; j++) mp[a[i + 1] * n + a[j]]++;
      for (long long j = 0; j < i; j++) {
        long long key = a[j] * n + a[i];
        ans += mp[key];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

### Prompt

Please create a solution in cpp to the following problem:

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;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
const long long INF = numeric_limits<long long>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926535898;
const long long LIM = 100005;
long long fpow(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = fpow(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void sieve(long long n) {
  bool prime[5 * LIM];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++)
    if (prime[p] == true)
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
  prime[1] = 0;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
map<long long, long long> primeFactors(long long n) {
  map<long long, long long> mp;
  while (n % 2 == 0) {
    if (mp.count(2) == 1)
      mp[2]++;
    else
      mp.insert({2, 1});
    n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      if (mp.count(i) == 1)
        mp[i]++;
      else
        mp.insert({i, 1});
      n = n / i;
    }
  }
  if (n > 2) {
    if (mp.count(n) == 1)
      mp[n]++;
    else
      mp.insert({n, 1});
  }
  return mp;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  for (long long tt = 1; tt <= t; ++tt) {
    long long n, ans = 0;
    cin >> n;
    vector<long long> a(n);
    for (auto &x : a) cin >> x;
    ;
    vector<long long> mp(n * n + n + 1, 0);
    for (long long i = n - 3; i >= 1; i--) {
      for (long long j = i + 2; j < n; j++) mp[a[i + 1] * n + a[j]]++;
      for (long long j = 0; j < i; j++) {
        long long key = a[j] * n + a[i];
        ans += mp[key];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

```