#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second < b.second)
    return true;
  else
    return false;
}
bool sortbyboth(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first < b.first)
    return true;
  else if (a.first == b.first)
    return a.second < b.second;
  else
    return false;
}
bool sortff_resortss(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first < b.first)
    return true;
  else if (a.first == b.first)
    return a.second > b.second;
  else
    return false;
}
bool sortbystring(const string &a, const string &b) {
  string c = a + b;
  string d = b + a;
  if (c >= d)
    return true;
  else
    return false;
}
class CompareDist {
 public:
  bool operator()(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
    if (a.first < b.first)
      return true;
    else if (a.first == b.first)
      return a.second.first > b.second.first;
    else
      return false;
  }
};
long long modi(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long Logn(long long n, long long r) {
  return (n > r - 1) ? 1 + Logn(n / r, r) : 0;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modinv(long long n, long long p) { return power(n, p - 2, p); }
long long ncr(long long n, long long r, long long p) {
  if (r == 0) return 1;
  int n1 = n;
  long long fac[n1 + 1];
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
  return (fac[n] * modinv(fac[r], p) % p * modinv(fac[n - r], p) % p) % p;
}
int spf[10000001];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < 10000001; i++) spf[i] = i;
  for (int i = 4; i < 10000001; i += 2) spf[i] = 2;
  for (int i = 3; i * i < 10000001; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < 10000001; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<int> getFactorization(int x) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
bool isPowerOfTwo(int x) { return (x && !(x & (x - 1))); }
int count_one(int n) {
  int count = 0;
  while (n) {
    n = n & (n - 1);
    count++;
  }
  return count;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    for (int i = 0; i < n - 3; i++) {
      vector<int> m1(n + 1, 0), m2(n + 1, 0);
      long long sum = 0;
      for (int l = i + 3; l < n; l++) {
        m2[a[l]]++;
      }
      for (int j = i + 2; j < n - 1; j++) {
        sum += m2[a[j - 1]];
        m1[a[j - 1]]++;
        if (a[i] == a[j]) ans += sum;
        sum -= m1[a[j + 1]];
        m2[a[j + 1]]--;
      }
    }
    cout << ans << endl;
  }
  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;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second < b.second)
    return true;
  else
    return false;
}
bool sortbyboth(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first < b.first)
    return true;
  else if (a.first == b.first)
    return a.second < b.second;
  else
    return false;
}
bool sortff_resortss(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first < b.first)
    return true;
  else if (a.first == b.first)
    return a.second > b.second;
  else
    return false;
}
bool sortbystring(const string &a, const string &b) {
  string c = a + b;
  string d = b + a;
  if (c >= d)
    return true;
  else
    return false;
}
class CompareDist {
 public:
  bool operator()(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
    if (a.first < b.first)
      return true;
    else if (a.first == b.first)
      return a.second.first > b.second.first;
    else
      return false;
  }
};
long long modi(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long Logn(long long n, long long r) {
  return (n > r - 1) ? 1 + Logn(n / r, r) : 0;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modinv(long long n, long long p) { return power(n, p - 2, p); }
long long ncr(long long n, long long r, long long p) {
  if (r == 0) return 1;
  int n1 = n;
  long long fac[n1 + 1];
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
  return (fac[n] * modinv(fac[r], p) % p * modinv(fac[n - r], p) % p) % p;
}
int spf[10000001];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < 10000001; i++) spf[i] = i;
  for (int i = 4; i < 10000001; i += 2) spf[i] = 2;
  for (int i = 3; i * i < 10000001; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < 10000001; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<int> getFactorization(int x) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
bool isPowerOfTwo(int x) { return (x && !(x & (x - 1))); }
int count_one(int n) {
  int count = 0;
  while (n) {
    n = n & (n - 1);
    count++;
  }
  return count;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    for (int i = 0; i < n - 3; i++) {
      vector<int> m1(n + 1, 0), m2(n + 1, 0);
      long long sum = 0;
      for (int l = i + 3; l < n; l++) {
        m2[a[l]]++;
      }
      for (int j = i + 2; j < n - 1; j++) {
        sum += m2[a[j - 1]];
        m1[a[j - 1]]++;
        if (a[i] == a[j]) ans += sum;
        sum -= m1[a[j + 1]];
        m2[a[j + 1]]--;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

```