#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    long long n;
    cin >> n;
    long long a[n];
    long long left[n + 1];
    long long right[n + 1];
    for (long long j = 0; j < n; j++) {
      cin >> a[j];
      left[j] = 0;
      right[j] = 0;
    }
    left[n] = 0;
    left[a[0]]++;
    long long finalAns = 0;
    for (long long j = 1; j < n - 2; j++) {
      long long right[n + 1];
      for (long long k = 0; k <= n; k++) {
        right[k] = 0;
      }
      right[a[n - 1]]++;
      for (long long k = n - 2; k > j; k--) {
        finalAns += left[a[k]] * right[a[j]];
        right[a[k]]++;
      }
      left[a[j]]++;
    }
    cout << finalAns << endl;
  }
  return 0;
}
