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