#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; ++i) {
    cin >> v[i];
  }
  long long ans = 0;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    map<long long, long long> tp;
    long long cur = 0;
    for (long long j = i + 1; j < n; j++) {
      if (v[j] == v[i]) ans += cur;
      tp[v[j]]++;
      if (mp.count(v[j])) cur += mp[v[j]];
    }
    mp[v[i]]++;
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
