#include <bits/stdc++.h>
using namespace std;
void print() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  vector<long long> left(n + 1, 0), right(n + 1, 0);
  long long ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    right = vector<long long>(n + 1, 0);
    for (long long j = n - 1; j >= i + 1; j--) {
      ans += left[arr[j]] * right[arr[i]];
      right[arr[j]]++;
    }
    left[arr[i]]++;
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t) {
    --t;
    print();
  }
}
