#include <bits/stdc++.h>
using namespace std;
int T, N;
int v[(3000 + 10)];
int cl[(3000 + 10)];
int cr1[(3000 + 10)];
int cr2[(3000 + 10)];
int main() {
  scanf("%d", &T);
  while (T--) {
    fill(cl, cl + (3000 + 10), 0);
    fill(cr1, cr1 + (3000 + 10), 0);
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
      scanf("%d", v + i);
      cr1[v[i]]++;
    }
    long long tot = 0;
    for (int i = 0; i < N; i++) {
      cr1[v[i]]--;
      copy(cr1, cr1 + (3000 + 10), cr2);
      for (int j = i + 1; j < N; j++) {
        cr2[v[j]]--;
        tot += (long long)cl[v[j]] * (long long)cr2[v[i]];
      }
      cl[v[i]]++;
    }
    printf("%lld\n", tot);
  }
}
