#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int *arr = new int[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    vector<long long> lsum(n + 1, 0);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      vector<long long> rsum(n + 1, 0);
      for (int j = n - 1; j > i; j--) {
        ans += lsum[arr[j]] * rsum[arr[i]];
        rsum[arr[j]]++;
      }
      lsum[arr[i]]++;
    }
    cout << ans << "\n";
    delete[] arr;
  }
  return 0;
}
