#include <bits/stdc++.h>
using namespace std;
long long a[3005];
long long sum[3002][3002][3];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        sum[i][j][1] = 0;
        sum[i][j][0] = 0;
        sum[i][j][2] = 0;
      }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      for (int j = 1; j <= n; j++) {
        if (j == a[i]) {
          ans = ans + sum[j][a[i]][2];
          sum[j][a[i]][2] = sum[j][a[i]][2] + sum[j][a[i]][1];
          sum[j][a[i]][1] = sum[j][a[i]][1] + sum[j][a[i]][0];
          sum[j][a[i]][0] = sum[j][a[i]][0] + 1;
        } else {
          ans = ans + sum[j][a[i]][2];
          sum[a[i]][j][2] = sum[a[i]][j][2] + sum[a[i]][j][1];
          sum[j][a[i]][1] = sum[j][a[i]][1] + sum[j][a[i]][0];
          sum[a[i]][j][0] = sum[a[i]][j][0] + 1;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
