#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes(long long int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (prime[p]) cout << p << " ";
}
void seive(long long int n) {
  bool prime[n + 1];
  for (long long int i = 0; i <= n; ++i) prime[i] = true;
  prime[0] = prime[1] = false;
  for (long long int i = 2; i * i <= n; ++i) {
    if (prime[i]) {
      for (long long int j = i * i; j <= n; j += i) prime[j] = false;
    }
  }
  for (long long int i = 2; i <= n; ++i) {
    if (prime[i]) cout << i << " ";
  }
}
bool isPrime(long long int n) {
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long int isnCrOdd(long long int n, long long int r) {
  long long int a = r;
  long long int b = n - r;
  for (long long int i = 0; i < 30; i++) {
    long long int x = 1 << i;
    if ((x & a) && (x & b)) {
      return 0;
    }
  }
  return 1;
}
void dfsBuild(vector<vector<long long int>> &adj,
              vector<vector<long long int>> &g, long long int i, bool vis[]) {
  if (vis[i]) return;
  vis[i] = true;
  for (long long int j : g[i]) {
    if (!vis[j]) {
      adj[i].push_back(i);
      dfsBuild(adj, g, j, vis);
    }
  }
}
vector<vector<long long int>> buildUnw(long long int n) {
  vector<vector<long long int>> g(n);
  long long int u, v;
  for (long long int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<vector<long long int>> adj(n);
  bool vis[n];
  for (long long int i = 0; i < n; ++i) vis[i] = false;
  dfsBuild(adj, g, 0, vis);
  return adj;
}
void dfsBuild2(vector<vector<pair<long long int, long long int>>> &adj,
               vector<vector<pair<long long int, long long int>>> &g,
               long long int i, bool vis[]) {
  if (vis[i]) return;
  vis[i] = true;
  for (auto j : adj[i]) {
    if (!vis[j.first]) {
      adj[i].push_back(j);
      dfsBuild2(adj, g, j.first, vis);
    }
  }
}
vector<vector<pair<long long int, long long int>>> buildw(long long int n) {
  vector<vector<pair<long long int, long long int>>> g(n), adj(n);
  long long int u, v, w;
  for (long long int i = 0; i < n - 1; ++i) {
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  bool vis[n];
  for (long long int i = 0; i < n; ++i) vis[i] = false;
  dfsBuild2(adj, g, 0, vis);
  return adj;
}
void pb_200() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int solve(long long int arr[], long long int n) {
  vector<long long int> freqi(n + 1, 0), freql(n + 1, 0);
  long long int res = 0;
  for (long long int j = 0; j < n; ++j) {
    if (j - 1 >= 0) freqi[arr[j - 1]]++;
    for (long long int itr = 0; itr < n + 1; ++itr) freql[itr] = 0;
    for (long long int k = n - 1; k > j; --k) {
      if (k + 1 < n) freql[arr[k + 1]]++;
      res += freqi[arr[k]] * freql[arr[j]];
    }
  }
  return res;
}
int32_t main() {
  long long int x;
  cin >> x;
  while (x--) {
    long long int n;
    cin >> n;
    long long int *arr = new long long int[n];
    ;
    for (long long int i = 0; i < n; ++i) cin >> arr[i];
    cout << solve(arr, n) << endl;
  }
  return 0;
}

### Prompt

Your challenge is to write a cpp solution 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;
void SieveOfEratosthenes(long long int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (prime[p]) cout << p << " ";
}
void seive(long long int n) {
  bool prime[n + 1];
  for (long long int i = 0; i <= n; ++i) prime[i] = true;
  prime[0] = prime[1] = false;
  for (long long int i = 2; i * i <= n; ++i) {
    if (prime[i]) {
      for (long long int j = i * i; j <= n; j += i) prime[j] = false;
    }
  }
  for (long long int i = 2; i <= n; ++i) {
    if (prime[i]) cout << i << " ";
  }
}
bool isPrime(long long int n) {
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long int isnCrOdd(long long int n, long long int r) {
  long long int a = r;
  long long int b = n - r;
  for (long long int i = 0; i < 30; i++) {
    long long int x = 1 << i;
    if ((x & a) && (x & b)) {
      return 0;
    }
  }
  return 1;
}
void dfsBuild(vector<vector<long long int>> &adj,
              vector<vector<long long int>> &g, long long int i, bool vis[]) {
  if (vis[i]) return;
  vis[i] = true;
  for (long long int j : g[i]) {
    if (!vis[j]) {
      adj[i].push_back(i);
      dfsBuild(adj, g, j, vis);
    }
  }
}
vector<vector<long long int>> buildUnw(long long int n) {
  vector<vector<long long int>> g(n);
  long long int u, v;
  for (long long int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<vector<long long int>> adj(n);
  bool vis[n];
  for (long long int i = 0; i < n; ++i) vis[i] = false;
  dfsBuild(adj, g, 0, vis);
  return adj;
}
void dfsBuild2(vector<vector<pair<long long int, long long int>>> &adj,
               vector<vector<pair<long long int, long long int>>> &g,
               long long int i, bool vis[]) {
  if (vis[i]) return;
  vis[i] = true;
  for (auto j : adj[i]) {
    if (!vis[j.first]) {
      adj[i].push_back(j);
      dfsBuild2(adj, g, j.first, vis);
    }
  }
}
vector<vector<pair<long long int, long long int>>> buildw(long long int n) {
  vector<vector<pair<long long int, long long int>>> g(n), adj(n);
  long long int u, v, w;
  for (long long int i = 0; i < n - 1; ++i) {
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  bool vis[n];
  for (long long int i = 0; i < n; ++i) vis[i] = false;
  dfsBuild2(adj, g, 0, vis);
  return adj;
}
void pb_200() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int solve(long long int arr[], long long int n) {
  vector<long long int> freqi(n + 1, 0), freql(n + 1, 0);
  long long int res = 0;
  for (long long int j = 0; j < n; ++j) {
    if (j - 1 >= 0) freqi[arr[j - 1]]++;
    for (long long int itr = 0; itr < n + 1; ++itr) freql[itr] = 0;
    for (long long int k = n - 1; k > j; --k) {
      if (k + 1 < n) freql[arr[k + 1]]++;
      res += freqi[arr[k]] * freql[arr[j]];
    }
  }
  return res;
}
int32_t main() {
  long long int x;
  cin >> x;
  while (x--) {
    long long int n;
    cin >> n;
    long long int *arr = new long long int[n];
    ;
    for (long long int i = 0; i < n; ++i) cin >> arr[i];
    cout << solve(arr, n) << endl;
  }
  return 0;
}

```