#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &x : v) cin >> x;
    map<int, int> before;
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
      map<int, int> after;
      for (int j = n - 1; j > i; --j) {
        ans += before[v[j]] * after[v[i]];
        after[v[j]]++;
      }
      before[v[i]]++;
    }
    cout << ans << endl;
  }
}
