#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e5 + 100;
int N, a[MAXN];
void read() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
}
void solve() {
  read();
  long long ans = 0;
  for (int i = 0; i + 3 < N; i++) {
    vector<int> cnt(N + 1, 0);
    cnt[a[i + 1]]++;
    vector<int> cnt2(N + 1, 0);
    for (int j = N - 1; j >= i + 2; j--) {
      cnt2[a[j]]++;
    }
    long long ans2 = 0;
    for (int j = 0; j <= N; j++) {
      ans2 += cnt[j] * cnt2[j];
    }
    for (int k = i + 2; k + 1 < N; k++) {
      ans2 -= cnt[a[k]] * cnt2[a[k]];
      cnt2[a[k]]--;
      ans2 += cnt[a[k]] * cnt2[a[k]];
      if (a[i] == a[k]) {
        ans += ans2;
      }
      ans2 -= cnt[a[k]] * cnt2[a[k]];
      cnt[a[k]]++;
      ans2 += cnt[a[k]] * cnt2[a[k]];
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
