#include <bits/stdc++.h>
using namespace std;
int t, n, a[3010], lft[3010], rht[3010], cnt[3010];
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    long long ans = 0, now = 0;
    for (int i = 1; i <= n - 1; i++) {
      int k = i + 1;
      memset(lft, 0, sizeof(lft));
      memset(rht, 0, sizeof(rht));
      memset(cnt, 0, sizeof(cnt));
      for (int j = k + 1; j <= n; j++) {
        rht[a[j]]++;
      }
      while (k != n) {
        set<int> st;
        st.insert(a[k]);
        lft[a[k]]++;
        st.insert(a[k + 1]);
        rht[a[k + 1]]--;
        k++;
        for (auto to : st) {
          now = now - (long long)cnt[to];
          cnt[to] = lft[to] * rht[to];
          now = now + (long long)cnt[to];
        }
        if (a[i] == a[k]) {
          ans += now;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
