#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> pref(n + 1, vector<int>(n + 1));
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      for (int j = 1; j <= n; ++j) {
        pref[1 + i][j] = pref[i][j];
      }
      pref[1 + i][a[i]]++;
    }
    auto getpref = [&](int val, int i) { return pref[1 + i][val]; };
    auto getsuf = [&](int val, int i) { return pref[n][val] - pref[i][val]; };
    ll res = 0;
    for (int j = 1; j < n; ++j) {
      for (int k = j + 1; k < n - 1; ++k) {
        res += getpref(a[k], j - 1) * getsuf(a[j], k + 1);
      }
    }
    cout << res << "\n";
  }
}
