#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 5;
int T, n, a[maxn];
int cnt1[maxn], cnt2[maxn];
signed main() {
  scanf("%d", &T);
  while (T--) {
    long long ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    for (int i = 1; i <= n; i++) {
      memset(cnt1, 0, sizeof(cnt1));
      memset(cnt2, 0, sizeof(cnt2));
      for (int j = i + 2; j <= n; j++) cnt2[a[j]]++;
      long long now = 0;
      for (int j = i + 2; j < n; j++) {
        now -= cnt1[a[j]];
        cnt1[a[j - 1]]++, cnt2[a[j]]--;
        now += cnt2[a[j - 1]];
        if (a[i] == a[j]) ans += now;
      }
    }
    printf("%lld\n", ans);
  }
}
