#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n + 5];
  for (int i = 1; i <= n; i++) cin >> a[i];
  int d[n + 3][n + 3];
  memset(d, 0, sizeof d);
  for (int i = 1; i <= n; i++) {
    d[i][a[i]]++;
    for (int j = 0; j <= n; j++) {
      d[i][j] += d[i - 1][j];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans += (long long)(d[i - 1][a[j]] * (d[n][a[i]] - d[j][a[i]]));
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
