#include <bits/stdc++.h>
using namespace std;
long long a[1000005];
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long count = 0;
  vector<long long> l(3005);
  for (long long j = 0; j < n; j++) {
    vector<long long> r(3005);
    for (long long k = n - 1; k > j; k--) {
      count += l[a[k]] * r[a[j]];
      r[a[k]]++;
    }
    l[a[j]]++;
  }
  cout << count << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
