#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
template <typename T>
void read(T &x) {
  bool neg = false;
  unsigned char c = getchar();
  for (; (c ^ 48) > 9; c = getchar())
    if (c == '-') neg = true;
  for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
  if (neg) x = -x;
}
int t, n, a[N], p[N][N];
long long ans;
inline int lowbit(int x) { return x & -x; }
void add(int *c, int x) {
  for (++x; x <= n; x += lowbit(x)) ++c[x - 1];
}
int sum(int *c, int x) {
  int ans = 0;
  for (; x; x -= lowbit(x)) ans += c[x - 1];
  return ans;
}
int sum(int *c, int l, int r) { return sum(c, r) - sum(c, l); }
int main() {
  read(t);
  while (t--) {
    read(n);
    for (int i = 0, i_end = n; i < i_end; ++i) read(a[i]), --a[i];
    for (int i = 0, i_end = n; i < i_end; ++i)
      for (int j = 0, j_end = n; j < j_end; ++j) p[i][j] = 0;
    for (int i = 0, i_end = n; i < i_end; ++i)
      for (int j = 0, j_end = n; j < j_end; ++j)
        if (a[i] == a[j]) add(p[i], j);
    ans = 0ll;
    for (int i = 0, i_end = n; i < i_end; ++i)
      for (int j = i + 1, j_end = n; j < j_end; ++j) {
        int t = sum(p[j], 0, i) * sum(p[i], j + 1, n);
        ans += t;
      }
    printf("%lld\n", ans);
  }
  return 0;
}
