#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1);
template <class A, class B>
std::ostream& operator<<(std::ostream& st, const std::pair<A, B> p) {
  st << "(" << p.first << ", " << p.second << ")";
  return st;
}
using namespace std;
const int MAXN = 3 << 10;
int A[MAXN], n;
std::vector<int> freq;
vector<vector<long long>> cnt2, cnt3;
void tc() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) {
    scanf("%d", A + i);
    A[i]--;
  }
  freq.clear();
  cnt2.clear();
  cnt3.clear();
  freq.resize(n, 0);
  cnt2.resize(n, vector<long long>(n, 0));
  cnt3.resize(n, vector<long long>(n, 0));
  long long ans = 0;
  for (int i = 0; i < (n); i++) {
    int x = A[i];
    for (int i = 0; i < (n); i++) ans += cnt3[i][x];
    for (int i = 0; i < (n); i++) cnt3[x][i] += cnt2[x][i];
    for (int i = 0; i < (n); i++) cnt2[i][x] += freq[i];
    freq[x]++;
  }
  printf("%lld\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) tc();
  return 0;
}
