#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e3;
long long cnt1[mxN + 1], cnt2[mxN + 1], a[mxN + 1];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  memset(cnt1, 0, sizeof(cnt1));
  ;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    memset(cnt2, 0, sizeof(cnt2));
    ;
    for (int j = n - 1; j > i; j--) {
      ans += cnt1[a[j]] * cnt2[a[i]];
      cnt2[a[j]]++;
    }
    cnt1[a[i]]++;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
