#include <bits/stdc++.h>
#pragma comment(linker, "/stack:512000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
ll mod = 1e9 + 7;
namespace {
ll mul(ll a, ll b) {
  ll val = a * b - (ll)((ld)a * b / mod) * mod;
  if (val < 0) val += mod;
  if (val >= mod) val -= mod;
  return val;
}
ll poww(ll a, ll b) {
  ll val = 1;
  a %= mod;
  while (b > 0) {
    if (b % 2) val = mul(a, val);
    a = mul(a, a);
    b >>= 1;
  }
  return val % mod;
}
ll inv(ll a) { return poww(a, mod - 2); }
}  // namespace
ll const maxn = 1e6 + 6;
void B() {
  ll q;
  cin >> q;
  while (q--) {
    ll p, f;
    cin >> p >> f;
    ll cnts, cntw;
    cin >> cnts >> cntw;
    ll s, w;
    cin >> s >> w;
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    ll sum = p + f;
    ll ss = min(sum / s, cnts);
    ll ost = sum - ss * s;
    ll ww = min(ost / s, cntw);
    bool ff = true;
    for (ll wwp = 0; wwp <= ww; wwp++) {
      if (wwp * w > p) break;
      ll ostp = p - wwp * w;
      ll ssp = ostp / s;
      ll wwf = ww - wwp;
      ll ssf = ss - ssp;
      assert(wwf + ssf + ssp + wwp == ww + ss);
      if (wwf * w + ssf * s <= f) ff = false;
    }
    cout << max(0LL, ss + ww - ff) << '\n';
  }
}
ll pref[3005][3005], suf[3005][3005];
void restore() {
  for (ll i = 0; i < 3005; i++) {
    for (ll j = 0; j < 3005; j++) {
      pref[i][j] = 0;
      suf[i][j] = 0;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll q;
  cin >> q;
  while (q--) {
    restore();
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
      cin >> a[i];
    }
    pref[0][a[0]]++;
    for (ll i = 1; i < n; i++) {
      for (ll x = 0; x < 3005; x++) {
        pref[i][x] = pref[i - 1][x];
      }
      pref[i][a[i]]++;
    }
    suf[n - 1][a[n - 1]]++;
    for (ll i = n - 2; i >= 0; i--) {
      for (ll x = 0; x < 3005; x++) {
        suf[i][x] = suf[i + 1][x];
      }
      suf[i][a[i]]++;
    }
    ll ans = 0;
    for (ll i = 1; i < n; i++) {
      for (ll j = i + 1; j < n - 1; j++) {
        ans += pref[i - 1][a[j]] * suf[j + 1][a[i]];
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

### Prompt

Create a solution in Cpp for 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>
#pragma comment(linker, "/stack:512000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
ll mod = 1e9 + 7;
namespace {
ll mul(ll a, ll b) {
  ll val = a * b - (ll)((ld)a * b / mod) * mod;
  if (val < 0) val += mod;
  if (val >= mod) val -= mod;
  return val;
}
ll poww(ll a, ll b) {
  ll val = 1;
  a %= mod;
  while (b > 0) {
    if (b % 2) val = mul(a, val);
    a = mul(a, a);
    b >>= 1;
  }
  return val % mod;
}
ll inv(ll a) { return poww(a, mod - 2); }
}  // namespace
ll const maxn = 1e6 + 6;
void B() {
  ll q;
  cin >> q;
  while (q--) {
    ll p, f;
    cin >> p >> f;
    ll cnts, cntw;
    cin >> cnts >> cntw;
    ll s, w;
    cin >> s >> w;
    if (s > w) {
      swap(s, w);
      swap(cnts, cntw);
    }
    ll sum = p + f;
    ll ss = min(sum / s, cnts);
    ll ost = sum - ss * s;
    ll ww = min(ost / s, cntw);
    bool ff = true;
    for (ll wwp = 0; wwp <= ww; wwp++) {
      if (wwp * w > p) break;
      ll ostp = p - wwp * w;
      ll ssp = ostp / s;
      ll wwf = ww - wwp;
      ll ssf = ss - ssp;
      assert(wwf + ssf + ssp + wwp == ww + ss);
      if (wwf * w + ssf * s <= f) ff = false;
    }
    cout << max(0LL, ss + ww - ff) << '\n';
  }
}
ll pref[3005][3005], suf[3005][3005];
void restore() {
  for (ll i = 0; i < 3005; i++) {
    for (ll j = 0; j < 3005; j++) {
      pref[i][j] = 0;
      suf[i][j] = 0;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll q;
  cin >> q;
  while (q--) {
    restore();
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
      cin >> a[i];
    }
    pref[0][a[0]]++;
    for (ll i = 1; i < n; i++) {
      for (ll x = 0; x < 3005; x++) {
        pref[i][x] = pref[i - 1][x];
      }
      pref[i][a[i]]++;
    }
    suf[n - 1][a[n - 1]]++;
    for (ll i = n - 2; i >= 0; i--) {
      for (ll x = 0; x < 3005; x++) {
        suf[i][x] = suf[i + 1][x];
      }
      suf[i][a[i]]++;
    }
    ll ans = 0;
    for (ll i = 1; i < n; i++) {
      for (ll j = i + 1; j < n - 1; j++) {
        ans += pref[i - 1][a[j]] * suf[j + 1][a[i]];
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

```