#include <bits/stdc++.h>
using namespace std;
long long t, n, a[3005], sum[3005][3005], cnt[3005];
signed main(void) {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld", &n);
    for (long long i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= n; j++) {
        sum[i][j] = sum[i - 1][j] + (a[i] == j);
      }
    }
    long long ans = 0;
    for (long long j = 2; j <= n; j++) {
      for (long long k = j + 1; k <= n; k++) {
        ans += sum[j - 1][a[k]] * (sum[n][a[j]] - sum[k][a[j]]);
      }
    }
    cout << ans << '\n';
  }
}
