#include <bits/stdc++.h>
using namespace std;
void input() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  input();
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    unordered_map<long long int, long long int> mp;
    long long int ans = 0;
    for (long long int j = n - 1; j >= 0; j--) {
      long long int k = j + 1;
      for (long long int l = k + 1; l < n; l++) {
        mp[(a[k] * n + a[l])]++;
      }
      for (long long int i = 0; i < j; i++) ans += mp[(a[i] * n + a[j])];
    }
    cout << ans << endl;
  }
  return 0;
}
