#include <bits/stdc++.h>
using namespace std;
ifstream fin("AAtest.in.txt");
long long t, n, ma[5005], pal[5005], vas, su;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> ma[i];
    memset(pal, 0, sizeof(pal));
    vas = 0;
    for (int i = n - 1; i >= 0; i--) {
      su = 0;
      for (int j = i - 1; j >= 0; j--) {
        if (ma[j] == ma[i]) vas += su;
        su += pal[ma[j]];
      }
      pal[ma[i]]++;
    }
    cout << vas << "\n";
  }
}
