#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int t, n;
int a[3005];
int suff[3005][3005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    fill(suff[n], suff[n] + 1 + n, 0);
    for (int i = n; i > 0; --i) {
      if (i != n) {
        for (int j = 1; j <= n; ++j) {
          suff[i][j] = suff[i + 1][j];
        }
      }
      ++suff[i][a[i]];
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
      vector<int> cnt(n + 1, 0);
      ll curr = 0;
      for (int j = i + 1; j <= n; ++j) {
        if (a[i] == a[j]) {
          ans += curr - cnt[a[j]];
        }
        curr -= cnt[a[j]];
        ++cnt[a[j]];
        curr += suff[j + 1][a[j]];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
