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