#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> n;
    long long a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long mp[(n + 1) * (n + 1)];
    memset(mp, 0, sizeof(mp));
    for (j = n - 1; j >= 0; j--) {
      k = j + 1;
      for (long long l = k + 1; l < n; l++) {
        mp[a[k] * n + a[l]]++;
      }
      for (i = j - 1; i >= 0; i--) {
        ans += mp[a[i] * n + a[j]];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
