#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
int n, a[maxn], num[maxn][maxn];
vector<int> pos[maxn];
long long ans = 0;
int main() {
  register int t, i, j;
  scanf("%d", &t);
  while (t--) {
    ans = 0;
    memset(num, 0, sizeof(num));
    for (i = 1; i <= n; i++) pos[i].clear();
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      num[i][a[i]] += 1;
      for (j = 1; j <= n; j++) {
        num[i][j] += num[i - 1][j];
      }
      pos[a[i]].push_back(i);
    }
    for (i = 1; i <= n; i++) {
      if (pos[i].size() > 1) {
        for (j = 0; j < pos[i].size(); j++) {
          int p1 = pos[i][j];
          long long tmp = 0;
          for (int k1 = 1; k1 <= n; k1++) {
            tmp += (num[n][k1] - num[p1][k1]) * num[p1 - 1][k1];
          }
          for (int k2 = 1; k2 < p1 - 1; k2++) {
            tmp -= num[n][a[k2]] - num[p1][a[k2]];
            if (a[k2] == a[p1]) ans += tmp;
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
}
