#include <bits/stdc++.h>
using namespace std;
int a[3005];
int c[3005][3005], l[3005][3005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i + 1];
    for (int i = 0; i < 3001; i++) l[1][i] = 0;
    for (int i = 2; i <= n; i++) {
      for (int j = 0; j < 3001; j++) {
        l[i][j] = l[i - 1][j];
      }
      l[i][a[i - 1]] = 1 + l[i - 1][a[i - 1]];
    }
    for (int i = 0; i < 3001; i++) c[n][i] = 0;
    for (int i = n - 1; i >= 1; i--) {
      for (int j = 0; j < 3001; j++) {
        c[i][j] = c[i + 1][j];
      }
      c[i][a[i + 1]] = c[i][a[i + 1]] + 1;
    }
    long long ans = 0;
    for (int i = 2; i <= n - 2; i++) {
      for (int j = i + 1; j <= n - 1; j++) {
        long long cnt1 = 0, cnt2 = 0, index1 = i, index2 = j;
        cnt1 = l[i][a[j]];
        cnt2 = c[j][a[i]];
        ans += cnt1 * cnt2;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
