#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e18 + 100;
vector<long long> v[N];
long long a[3005], pref[3005][3005];
long long get(long long l, long long r, long long x) {
  return pref[r][x] - pref[l - 1][x];
}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= n; ++j) pref[i][j] = 0;
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= n; ++j)
      pref[i][j] = pref[i - 1][j] + (a[i] == j);
  long long cnt = 0;
  for (long long i = 1; i <= n; ++i)
    for (long long j = i + 1; j <= n; ++j)
      cnt += get(1, i - 1, a[j]) * get(j + 1, n, a[i]);
  cout << cnt << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long q;
  cin >> q;
  while (q--) solve();
  return 0;
}
