#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min3(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
long long max3(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
long long ceil1(long long x, long long y) {
  if (x % y)
    return (x + y) / y;
  else
    return x / y;
}
long long NC = 100;
long long N = 1e7 + 9;
const long long second = 1e6 + 7;
long long mod(long long n);
long long gcd(long long a, long long b);
long long modM(long long n, long long m);
long long modA(long long n, long long m);
long long modS(long long n, long long m);
long long power(long long a, long long b);
void pra(long long a[], long long n);
void ipgraph(long long n, long long m);
vector<vector<long long> > v;
vector<bool> vis;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  ;
  for (long long i = 0; i < n; i++) a[i]--;
  vector<long long> rec(n * n + n);
  long long ans = 0;
  for (long long j = n - 1; j > -1; j--) {
    long long k = j + 1;
    for (long long l = k + 1; l < n; l++) {
      rec[n * a[k] + a[l]]++;
    }
    for (long long i = 0; i < j; i++) {
      ans += rec[n * a[i] + a[j]];
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  cerr << '\n'
       << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
void ipgraph(long long n, long long m) {
  v.assign(n, {});
  vis.assign(n, 0);
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    v[y].push_back(x);
    v[x].push_back(y);
  }
}
long long gcd(long long a, long long b) {
  if (b > a) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long c = power(a, b / 2);
  if (b % 2 == 0)
    return modM(c, c);
  else
    return modM(modM(c, c), a);
}
void pra(long long a[], long long n) {
  for (long long i = 0; i < n; i++) cout << a[i] << " ";
  cout << '\n';
}
long long mod(long long n) { return (n % N + N) % N; }
long long modM(long long n, long long m) { return ((n % N * m % N) + N) % N; }
long long modA(long long n, long long m) { return ((n % N + m % N) + N) % N; }
long long modS(long long n, long long m) { return ((n % N - m % N) + N) % N; }

### Prompt

Construct a cpp code solution to the problem outlined:

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 min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min3(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
long long max3(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
long long ceil1(long long x, long long y) {
  if (x % y)
    return (x + y) / y;
  else
    return x / y;
}
long long NC = 100;
long long N = 1e7 + 9;
const long long second = 1e6 + 7;
long long mod(long long n);
long long gcd(long long a, long long b);
long long modM(long long n, long long m);
long long modA(long long n, long long m);
long long modS(long long n, long long m);
long long power(long long a, long long b);
void pra(long long a[], long long n);
void ipgraph(long long n, long long m);
vector<vector<long long> > v;
vector<bool> vis;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  ;
  for (long long i = 0; i < n; i++) a[i]--;
  vector<long long> rec(n * n + n);
  long long ans = 0;
  for (long long j = n - 1; j > -1; j--) {
    long long k = j + 1;
    for (long long l = k + 1; l < n; l++) {
      rec[n * a[k] + a[l]]++;
    }
    for (long long i = 0; i < j; i++) {
      ans += rec[n * a[i] + a[j]];
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  cerr << '\n'
       << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
void ipgraph(long long n, long long m) {
  v.assign(n, {});
  vis.assign(n, 0);
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    v[y].push_back(x);
    v[x].push_back(y);
  }
}
long long gcd(long long a, long long b) {
  if (b > a) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long c = power(a, b / 2);
  if (b % 2 == 0)
    return modM(c, c);
  else
    return modM(modM(c, c), a);
}
void pra(long long a[], long long n) {
  for (long long i = 0; i < n; i++) cout << a[i] << " ";
  cout << '\n';
}
long long mod(long long n) { return (n % N + N) % N; }
long long modM(long long n, long long m) { return ((n % N * m % N) + N) % N; }
long long modA(long long n, long long m) { return ((n % N + m % N) + N) % N; }
long long modS(long long n, long long m) { return ((n % N - m % N) + N) % N; }

```