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