#include<bits/stdc++.h>
using namespace std;
const double EPS = 1e-7;

int noOfPeople , Distance , walkingSpeed , busSpeed , busSeats;
int groups;

bool check(double possibleTime){
	// now the possibleTime represents the total required time to finish the journey

	double timePassed = 0.0;
	for(int i = 0 ;i < groups ;i ++){
		// we will go over each group and till now the current group haven't riden the bus yet so till now this group have walked a distance
		// which is equal to timePassed * walkingSpeed
		// ok now this group will ride the bus ... if we considerd that this group will ride it for T seconds .. this will make this group
		// go distance equal to busRide = T * busSpeed and will leave this group to walk the remaining distance in the remaining time left which is
		// remaining time = possibleTime - timePassed - T
		// This group also have a total remaining distance equal to distance - timePassed * walkingSpeed . therefore this remaining distance
		// should equal to the busRide distance + walkingSpeed * remaining time which is
		// distance - timePassed * walkingSpeed = T * busSpeed + (possibleTime - timePassed - T) * walkingSpeed
		// distance - timePassed * walkingSpeed = T * busSpeed + possibleTime * walkingSpeed - timePassed * walkingSpeed - T * walkingSpeed
		// distance - possibleTime * walkingSpeed = T * ( busSpeed - walkingSpeed )
		// T = (distance - possibleTime * walkingSpeed) / ( busSpeed - walkingSpeed )
		double T = (Distance - possibleTime * 1.0 * walkingSpeed) / ( 1.0 * busSpeed - walkingSpeed );

		timePassed += T;

		if(i + 1 < groups){ // that means i have to calculate the time required for the bus to come back for the next group

			// before the bus moved with distance T * busSpeed .. the bus and this next group were in the same place
			// then the bus were in location T * busSpeed while the next group were in location T * walkingSpeed after T seconds
			// we will suppose that after M seconds (meeting time required) they'll meet in a location when the bus is moving towards
			// the next group right now with backwordDistance = -M * busSpeed and the next group is moving with M * walkingSpeed
			// therefore the following equality should hold ...
			// T * walkingSpeed + M * walkingSpeed = T * busSpeed - M * busSpeed
			// M * walkingSpeed + M * busSpeed = T * busSpeed - T * walkingSpeed
			// M * ( walkingSpeed + busSpeed ) = T * busSpeed - T * walkingSpeed
			// M = ( T * busSpeed - T * walkingSpeed ) / ( walkingSpeed + busSpeed )

			double M = ( T * 1.0 * busSpeed - T * walkingSpeed ) / ( 1.0 * walkingSpeed + busSpeed );

			// we've to add this time to the total time passed now
			timePassed += M;
		}
	}
	return timePassed <= possibleTime;

}

int main(){

	scanf("%d%d%d%d%d" , &noOfPeople , &Distance , &walkingSpeed , &busSpeed , &busSeats);

	// number of groups that will ride the bus
	groups = noOfPeople / busSeats;
	if(noOfPeople % busSeats != 0){
		// which means there're still some people and there number is less than the busSeats available so i will add another group for them
		groups ++;
	}

	// the amount of time required if all the people will only walk to finish their journey
	double walkingAllTheJourney = (1.0 * Distance) / double(walkingSpeed) ;

	double left = 0.0 , right = walkingAllTheJourney , answer = 0.0;

	while(right - left >= EPS){

		double mid = (left + right) / 2.0;

		if(check(mid) == true){
			answer = mid;
			right = mid;
		}
		else
			left = mid;

	}

	printf("%.12lf\n" , answer);

}


#include<bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;

int noOfPeople , Distance , walkingSpeed , busSpeed , busSeats;
int groups;

bool check(double possibleTime){
	// now the possibleTime represents the total required time to finish the journey

	double timePassed = 0.0;
	for(int i = 0 ;i < groups ;i ++){
		// we will go over each group and till now the current group haven't riden the bus yet so till now this group have walked a distance
		// which is equal to timePassed * walkingSpeed
		// ok now this group will ride the bus ... if we considerd that this group will ride it for T seconds .. this will make this group
		// go distance equal to busRide = T * busSpeed and will leave this group to walk the remaining distance in the remaining time left which is
		// remaining time = possibleTime - timePassed - T
		// This group also have a total remaining distance equal to distance - timePassed * walkingSpeed . therefore this remaining distance
		// should equal to the busRide distance + walkingSpeed * remaining time which is
		// distance - timePassed * walkingSpeed = T * busSpeed + (possibleTime - timePassed - T) * walkingSpeed
		// distance - timePassed * walkingSpeed = T * busSpeed + possibleTime * walkingSpeed - timePassed * walkingSpeed - T * walkingSpeed
		// distance - possibleTime * walkingSpeed = T * ( busSpeed - walkingSpeed )
		// T = (distance - possibleTime * walkingSpeed) / ( busSpeed - walkingSpeed )
		double T = (Distance - possibleTime * 1.0 * walkingSpeed) / ( 1.0 * busSpeed - walkingSpeed );

		timePassed += T;

		if(i + 1 < groups){ // that means i have to calculate the time required for the bus to come back for the next group

			// before the bus moved with distance T * busSpeed .. the bus and this next group were in the same place
			// then the bus were in location T * busSpeed while the next group were in location T * walkingSpeed after T seconds
			// we will suppose that after M seconds (meeting time required) they'll meet in a location when the bus is moving towards
			// the next group right now with backwordDistance = -M * busSpeed and the next group is moving with M * walkingSpeed
			// therefore the following equality should hold ...
			// T * walkingSpeed + M * walkingSpeed = T * busSpeed - M * busSpeed
			// M * walkingSpeed + M * busSpeed = T * busSpeed - T * walkingSpeed
			// M * ( walkingSpeed + busSpeed ) = T * busSpeed - T * walkingSpeed
			// M = ( T * busSpeed - T * walkingSpeed ) / ( walkingSpeed + busSpeed )

			double M = ( T * 1.0 * busSpeed - T * walkingSpeed ) / ( 1.0 * walkingSpeed + busSpeed );

			// we've to add this time to the total time passed now
			timePassed += M;
		}
	}
	return timePassed <= possibleTime;

}

int main(){

	scanf("%d%d%d%d%d" , &noOfPeople , &Distance , &walkingSpeed , &busSpeed , &busSeats);

	// number of groups that will ride the bus
	groups = noOfPeople / busSeats;
	if(noOfPeople % busSeats != 0){
		// which means there're still some people and there number is less than the busSeats available so i will add another group for them
		groups ++;
	}

	// the amount of time required if all the people will only walk to finish their journey
	double walkingAllTheJourney = (1.0 * Distance) / double(walkingSpeed) ;

	double left = 0.0 , right = walkingAllTheJourney , answer = 0.0;

	for(double sz = right * 0.5 ; sz > EPS ; sz *= 0.5){
		double mid = sz + answer;
		if(check(mid) == false)
			answer += sz;
	}

	printf("%.12lf\n" , answer);

}


#include<bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;

int noOfPeople , Distance , walkingSpeed , busSpeed , busSeats;
int groups;

bool check(double possibleTime){
	// now the possibleTime represents the total required time to finish the journey

	/*
	double timePassed = 0.0;
	for(int i = 0 ;i < groups ;i ++){
		// we will go over each group and till now the current group haven't riden the bus yet so till now this group have walked a distance
		// which is equal to timePassed * walkingSpeed
		// ok now this group will ride the bus ... if we considerd that this group will ride it for T seconds .. this will make this group
		// go distance equal to busRide = T * busSpeed and will leave this group to walk the remaining distance in the remaining time left which is
		// remaining time = possibleTime - timePassed - T
		// This group also have a total remaining distance equal to distance - timePassed * walkingSpeed . therefore this remaining distance
		// should equal to the busRide distance + walkingSpeed * remaining time which is
		// distance - timePassed * walkingSpeed = T * busSpeed + (possibleTime - timePassed - T) * walkingSpeed
		// distance - timePassed * walkingSpeed = T * busSpeed + possibleTime * walkingSpeed - timePassed * walkingSpeed - T * walkingSpeed
		// distance - possibleTime * walkingSpeed = T * ( busSpeed - walkingSpeed )
		// T = (distance - possibleTime * walkingSpeed) / ( busSpeed - walkingSpeed )
		double T = (Distance - possibleTime * 1.0 * walkingSpeed) / ( 1.0 * busSpeed - walkingSpeed );

		timePassed += T;

		if(i + 1 < groups){ // that means i have to calculate the time required for the bus to come back for the next group

			// before the bus moved with distance T * busSpeed .. the bus and this next group were in the same place
			// then the bus were in location T * busSpeed while the next group were in location T * walkingSpeed after T seconds
			// we will suppose that after M seconds (meeting time required) they'll meet in a location when the bus is moving towards
			// the next group right now with backwordDistance = -M * busSpeed and the next group is moving with M * walkingSpeed
			// therefore the following equality should hold ...
			// T * walkingSpeed + M * walkingSpeed = T * busSpeed - M * busSpeed
			// M * walkingSpeed + M * busSpeed = T * busSpeed - T * walkingSpeed
			// M * ( walkingSpeed + busSpeed ) = T * busSpeed - T * walkingSpeed
			// M = ( T * busSpeed - T * walkingSpeed ) / ( walkingSpeed + busSpeed )

			double M = ( T * 1.0 * busSpeed - T * walkingSpeed ) / ( 1.0 * walkingSpeed + busSpeed );

			// we've to add this time to the total time passed now
			timePassed += M;
		}
	}
	*/

	// also we can see that both of the equations doesn't depend on the timepassed variable so we can calculate required time without a loop
	double optT = (Distance - possibleTime * 1.0 * walkingSpeed) / ( 1.0 * busSpeed - walkingSpeed ) ;
	double optM = (groups - 1) * ( optT * 1.0 * busSpeed - optT * walkingSpeed ) / ( 1.0 * walkingSpeed + busSpeed ) ;
	double optTimePassed = groups * optT + optM ;
	return optTimePassed <= possibleTime;

}

int main(){

	scanf("%d%d%d%d%d" , &noOfPeople , &Distance , &walkingSpeed , &busSpeed , &busSeats);

	// number of groups that will ride the bus
	groups = noOfPeople / busSeats;
	if(noOfPeople % busSeats != 0){
		// which means there're still some people and there number is less than the busSeats available so i will add another group for them
		groups ++;
	}

	// the amount of time required if all the people will only walk to finish their journey
	double walkingAllTheJourney = (1.0 * Distance) / double(walkingSpeed) ;

	double left = 0.0 , right = walkingAllTheJourney , answer = 0.0;

	for(double sz = right * 0.5 ; sz > EPS ; sz *= 0.5){
		double mid = sz + answer;
		if(check(mid) == false)
			answer += sz;
	}

	printf("%.12lf\n" , answer);

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll MOD=1e9+7;
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define chal(n) for(ll i=0;i<n;i++)
#define chali(n) for(ll i=1;i<=n;++i)
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)9
#define sl1(a) scanf("%lld",&a)
#define sl2(a,b) scanf("%lld%lld",&a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
bool IsPowerOfTwo(ll x){ return (x != 0) && ((x & (x - 1)) == 0);}
ll poer(ll a,ll b){ll rs=1; while(b>0) { if(b&1) rs*=a; a*=a; b/=2;} return rs;}
ll mod_poer(ll a,ll b,ll mo){ll rs=1; while(b>0) { if(b&1) rs=(rs*a)%mo; a=(a*a)%mo; b/=2;} return rs%mo;}
ll d,x,y;
void ext_euclid(ll a,ll b){ if(b==0){d=a;x=1;y=0;}else{ext_euclid(b,a%b);ll temp=x;x=y;y=temp-(a/b)*y;}}
ll mod_inverse1(ll a,ll m){ext_euclid(a,m);return (x%m+m)%m;}
ll mod_inverse2(ll a,ll m){return mod_poer(a,m-2,m);}
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}

// never take ll as return type of find operation in strings
// never take d,x,y as variables

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

   ll n,k;
   double l,v1,v2;
   cin>>n>>l>>v1>>v2>>k;
   ll num=n/k+(n%k!=0);
   double low=0,high=l/v1,mid,timepassed;
   while((high-low)>=5e-8)
   {
       mid=(low+high)/2;
       timepassed=0;
       for(ll i=0;i<num;++i)
       {
           double re=(l-(mid*v1))/(v2-v1);
           timepassed+=re;
           if(i+1<num)
           {
               double ry=re*((v2-v1)/(v2+v1));
               timepassed+=ry;
           }
       }
       if(timepassed>=mid)
        low=mid;
       else
        high=mid;
   }
   cout<<fixed<<setprecision(10)<<low<<endl;
   return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#include<time.h>
#define ll long long
#define PI acos(-1.0)
#define F first
#define S second
#define pb push_back
#define debug(x); printf("debug%d\n",x);
#define des(x); printf("des:%s\n",x+1);
#define rep(f,t) for(int i=f;i<=t;i++)
const ll INF=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
using namespace std;
double l,v1,v2;
int n,k;
int main()
{
    scanf("%d%lf%lf%lf%d",&n,&l,&v1,&v2,&k);
    double L=0;
    int p;
    p=n/k;
    if((n%k)>0)
        p++;
    L=l/(p*v2-(v2-v1)/(v2+v1)*v2*(p-1));
    printf("%.10f\n",(l-v2*L)/v1+L);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    double n,l,v1,v2,k;
    scanf("%lf%lf%lf%lf%lf",&n,&l,&v1,&v2,&k);
    int cnt=(n+k-1)/k;
    double d=l*(v1+v2)/((2.0*cnt-1)*v1+v2);
    double ans=d/v2+(l-d)/v1;
	printf("%.10f\n",ans);
}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-12;
const int N=100000+10,maxn=1200000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

int main()
{
    ll n,l,v1,v2,k;
    scanf("%lld%lld%lld%lld%lld",&n,&l,&v1,&v2,&k);
    ll te=n/k-1;
//    printf("%lld\n",te);
    if(n%k!=0)te++;
    double low=2.0*v1/(v1+v2)*v2;
    double t1=(double)l/(low*te+v2);
    double t2=(double)(v2-v1)/(v1+v2)*t1;
    double ans=(double)te*(t1+t2)+t1;
    printf("%.12f\n",ans);
    return 0;
}
/********************

********************/


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-12;
const int N=100000+10,maxn=1200000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

int main()
{
    ll n,l,v1,v2,k;
    scanf("%lld%lld%lld%lld%lld",&n,&l,&v1,&v2,&k);
    ll te=n/k-1;
    double low=2.0*v1/(v1+v2)*v2;
    double t1=(double)l/(low*te+v2);
    double t2=(double)(v2-v1)/(v1+v2)*t1;
    double ans=(double)te*(t1+t2)+t1;
    printf("%.12f\n",ans);
    return 0;
}
/********************

********************/


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-12;
const int N=100000+10,maxn=1200000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

int main()
{
    int n,l,v1,v2,k;
    scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k);
    int te=n/k-1;
    double low=2.0*v1*v2/(v1+v2);
    double t1=(double)l/(low*te+v2);
    double t2=(double)(v2-v1)/(v1+v2)*t1;
    double ans=te*(t1+t2)+t1;
    printf("%.12f\n",ans);
    return 0;
}
/********************

********************/


#include<bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	double n, l, v1, v2, k;
	cin >> n >> l >> v1 >> v2 >> k;

	double x = ceil(n / k);
	double b = x * (v1 + v2) - (x - 1) * (v2 - v1);
	double a = l * (v1 + v2) / b;

	double ans = a / v2 + (l - a) / v1;
	cout << fixed << setprecision(7) << ans << "\n";
}


#include<bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	double n, l, v1, v2, k;
	cin >> n >> l >> v1 >> v2 >> k;

	double x = ceil(n / k);
	double a = l * 3 / (3 + (x - 1) * 2);
	double b = l - a;

	double ans = a / v2 + b / v1;
	cout << fixed << setprecision(7) << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

double L,v1,v2;
int n,k,m,cnt;

bool check(double x)
{
    double tc = m*x/v2 + (m-1) * x * (1-v1/v2) / (v1+v2);//bus
    double tp = x/v2 + (L - x)/v1; //people
    if (tc<=tp)
        return true;
    else
        return false;
}

int main(){
    scanf("%d%lf%lf%lf%d",&n,&L,&v1,&v2,&k);

    m = n/k; if (n%k) m++;
    double l = 0 , r  = L,mid;
    while (cnt++<1000)
    {
        mid = (l+r)/2.0;
        if (check(mid)) l = mid;
        else r = mid;
    }
    printf("%.8f\n",l/v2+(L-l)/v1);

    return 0;

}


#include <bits/stdc++.h>
using namespace std;

double L,v1,v2;
int n,k,m,cnt;

bool check(double x)
{
    double tc = m*x/v2 + (m-1) * x * (1-v1/v2) / (v1+v2);//bus
    double tp = x/v2 + (L - x)/v1; //people
    if (tc<=tp)
        return true;
    else
        return false;
}

int main(){
    scanf("%d%lf%lf%lf%d",&n,&L,&v1,&v2,&k);

    m = n/k;
    double l = 0 , r  = L,mid;
    while (cnt++<1000)
    {
        mid = (l+r)/2.0;
        if (check(mid)) l = mid;
        else r = mid;
    }
    printf("%.8f\n",l/v2+(L-l)/v1);

    return 0;

}


// g++ -std=c++14

#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

lld n,l,v1,v2,k;

bool check(lld T){
  lld temp_time;
  lld time_esp = 0.0;
  lld st = 0.0;
  lld x,t;
  for(int i=0;i<ceil(n/k);i++){
    x = ((T-time_esp)*v1*v2 + v1*st - l*v2)/(v1-v2);
    t = (x - st)/(v2);
    if ((l-st)/v2 + time_esp > T) return false;
    time_esp+=t;
    st+=t*v1;
    if(!(i+1>=ceil(n/k))){
      t = (x - st)/(v1+v2);
      st += v1*t;
      time_esp += t;
    }
  }
  return true;
}

int main(){
  cin>>n>>l>>v1>>v2>>k;

  lld l1 = 0;
  lld r1 = (l*1.0)/v1;
  lld mid;
  lld ans;
  // tr(l1,r1);
  for(int i=0;i<=100;i++){
    mid = (l1+r1)/2;
    // tr(mid,check(mid));
    if(check(mid)){
      ans = mid;
      r1 = mid;
    }
    else{
      l1 = mid;
    }
  }
  printf("%0.8Lf\n",ans);
  return 0;
}


/*/ Author : Abhishek Chauhan /*/

#include<bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace std::chrono;
using namespace __gnu_pbds;
using namespace std;
#define ld long double
#define rep(i,n)             for(int i=0;i<n;i++)
#define int                  long long
#define pb                   push_back
#define mp                   make_pair
#define all(x)               x.begin(),x.end()
#define mod                  1000000007
#define umap                 unordered_map
#define trailzero(x)         __builtin_ctz(x)
#define bpop(x)              __builtin_popcountll((x))
#define fastio               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl                 '\n'

template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

template<class T>
T power(T x, T y){T res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
template<class T>
T powermod(T x, T y, T p){T res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}

struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(pair<int64_t,int64_t> Y) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
    }
};

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l,long long r){
    uniform_int_distribution<int64_t> generator(l,r);
    return generator(rng);
}
inline int64_t random_long(){
    uniform_int_distribution<int64_t> generator(LLONG_MIN,LLONG_MAX);
    return generator(rng);
}

void snow(){

   int n;
   ld l,v1,v2,k;
   cin>>n>>l>>v1>>v2>>k;
   int gp = (n+k-1)/k;
   ld low = 0;
   ld high = v1 * l;
   while((high-low)>=1e-7){
   	 ld mid = (high+low)/2;
   	 ld timepassed = 0;
     for(int i=0;i<gp;i++){
         ld dist_left = l - v1 * timepassed;
         ld x = (l - v1 * mid )/( v2 - v1 );
         timepassed+=x;
         if(i+1<gp){
            timepassed+= (x*v2 - x*v1) / ( v2 + v1 );
         }
     }
     if(timepassed > mid){
     	low = mid;
     }
     else{
     	high= mid;
     }
   }
   while(double(clock()/CLOCKS_PER_SEC)<1){

   }
   cout<<fixed<<setprecision(12)<<(high+low)/2<<endl;
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    auto start = high_resolution_clock::now();
    fastio;
    int _;
    _=1;
    // cin>>_;
    for(int i=1;i<=_;i++){
    	// cout<<"Case #"<<i<<": ";
    	snow();
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    #ifndef ONLINE_JUDGE
     cerr << "Time: " << duration.count()/1000.0 << endl;
    #endif
    return 0;
}


#include<bits/stdc++.h>
#define ll                 long long int
#define mod                1000000007
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 long double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15
struct lex_compare {
    bool operator() (ll x,ll y){
        return x > y;
    }
};

int main(){
    FIO;
    ll t; cin >> t;
    while(t--){
        ll n; cin >> n;
        ll arr[n]; forn(i,0,n) cin >> arr[i];
        unordered_map<ll,ll> dp[n], dp1[n], dp2[n];
        ll ans = 0;
        for(ll i = 0;i<n;i++){
            for(ll j = 0;j<i;j++){
                ll diff = (arr[i]-arr[j]);
                dp[i][diff] += 1;
                dp1[i][diff] += dp[j][-1*diff];
                dp2[i][diff] += dp1[j][-1*diff];

            }
        }
        for(ll i = 0;i<n;i++){
            for(auto j : dp2[i]){
                ans += j.ss;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize "trapv"
#define ll                 long long int
#define mod                1000000007
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 long double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15

struct ppp{
    char a;
    ll b,c,d;
};

ll N;

struct lex_compare {
    bool operator() (ppp p1, ppp p2){
        if(p1.a == p2.a){
            if(p1.b == p2.b) return p1.c < p2.c;
            else return p1.b < p2.b;
        }else{
            return p1.a < p2.a;
        }
    }
};

ll nc4(ll x){
    if(x >= 4){
        ll temp = (x*(x-1)*(x-2)*(x-3));
        temp /= 24;
        return temp;
    }
    return 0;
}

map<ll,vv(ll)> m;

bool comp(ll x, ll y){
    return m[x].size() < m[y].size();
}

int main(){
    FIO;
    ll t; cin >> t;
    while(t--){
        m.clear();
        ll n; cin >> n;
        vv(ll) arr(n); forn(i,0,n ) cin >> arr[i];
        ll ans = 0;

        vv(ll) v;
        forn(i,0,n){
            if(!m.count(arr[i])) v.pb(arr[i]);
            m[arr[i]].pb(i);
        }
        sort(all(v), comp);
        for(int i = 0;i<v.size();i++){
            ll x = v[i];
            ans += nc4(m[x].size());
            for(int j = i+1;j<v.size();j++){
                ll y = v[j];
                vv(ll) &v1 = m[x];
                vv(ll) &v2 = m[y];
                //dbgArr(v1, v1.size());
                //dbgArr(v2, v2.size());
                for(int i1 = 0;i1 <v1.size();i1++){
                    for(int i2 = i1+1;i2<v1.size();i2++){
                        int ind1 = v1[i1];
                        int ind2 = v1[i2];
                        ll c1 = (v2.end()-lower_bound(all(v2), ind1));
                        ll c2 = (v2.end()-lower_bound(all(v2), ind2));
                        ll c3 = (v2.size()-c1);
                        //dbg2(ind1,ind2);
                        //dbg2(c1, c2);
                        ans += ((c1-c2)*c2);
                        ans += ((c1-c2)*c3);
                    }
                }
            }
        }
        cout << ans << endl;

    }

    return 0;
}


#include<bits/stdc++.h>
#define ll                 long long int
#define mod                1000000007
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 long double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15
struct lex_compare {
    bool operator() (ll x,ll y){
        return x > y;
    }
};

ll dp[3000][2LL*3000+3], dp1[3000][2LL*3000+3], dp2[3000][2LL*3000+3];

int main(){
    FIO;
    ll t; cin >> t;
    memset(dp,0,sizeof(dp));
    memset(dp1,0,sizeof(dp1));
    memset(dp2,0,sizeof(dp2));
    while(t--){
        ll n; cin >> n;
        ll arr[n]; forn(i,0,n) cin >> arr[i];
        ll ans = 0;
        for(ll i = 0;i<n;i++){
            for(ll j = 0;j<i;j++){
                ll diff = (arr[i]-arr[j]);
                dp[i][diff+n] += 1;
                dp1[i][diff+n] += dp[j][-1*diff+n];
                dp2[i][diff+n] += dp1[j][-1*diff+n];
            }
        }
        for(ll i = 0;i<n;i++){
            for(int j = 0;j<2*n+3;j++){
                ans += dp2[i][j];
                dp[i][j] = dp2[i][j] = dp1[i][j] = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll                 long long int
#define mod                1000000007
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 long double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15
struct lex_compare {
    bool operator() (ll x,ll y){
        return x > y;
    }
};

vv(vv(long int)) dp(3000,vv(ll)(2*3000,0));
vv(vv(long int)) dp1(3000,vv(ll)(2*3000,0));

int main(){
    FIO;
    ll t; cin >> t;
    while(t--){
        ll n; cin >> n;
        ll arr[n]; forn(i,0,n) cin >> arr[i];

        ll ans = 0;
        for(ll i = 0;i<n;i++){
            for(ll j = 0;j<i;j++){
                ll diff = (arr[i]-arr[j]);
                dp[i][diff+n-1] += 1;

            }
        }
        for(ll i = 0;i<n;i++){
            for(ll j = 0;j<i;j++){
                ll diff = (arr[i]-arr[j]);
                dp1[i][diff+n-1] += dp[j][-1*diff+n-1];
            }
        }

        for(ll i = 0;i<n;i++){
            for(ll j = 0;j<2*n;j++){
                dp[i][j] = 0;
            }
        }

        for(ll i = 0;i<n;i++){
            for(ll j = 0;j<i;j++){
                ll diff = (arr[i]-arr[j]);
                dp[i][diff+n-1] += dp1[j][-1*diff+n-1];
            }
        }
        for(ll i = 0;i<n;i++){
            for(ll j = 0;j<2*n;j++){
                ans += dp[i][j];
                dp[i][j] = dp1[i][j] = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize "trapv"
#define ll                 long long int
#define mod                1000000007
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 long double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15

struct ppp{
    char a;
    ll b,c,d;
};

ll N;

struct lex_compare {
    bool operator() (ppp p1, ppp p2){
        if(p1.a == p2.a){
            if(p1.b == p2.b) return p1.c < p2.c;
            else return p1.b < p2.b;
        }else{
            return p1.a < p2.a;
        }
    }
};

ll nc4(ll x){
    if(x >= 4){
        ll temp = (x*(x-1)*(x-2)*(x-3));
        temp /= 24;
        return temp;
    }
    return 0;
}

int main(){
    FIO;
    ll t; cin >> t;
    while(t--){
        ll n; cin >> n;
        vv(ll) arr(n); forn(i,0,n ) cin >> arr[i];
        ll ans = 0;
        map<ll,vv(ll)> m;
        vv(ll) v;
        forn(i,0,n){
            if(!m.count(arr[i])) v.pb(arr[i]);
            m[arr[i]].pb(i);
        }
        for(int i = 0;i<v.size();i++){
            ll x = v[i];
            ans += nc4(m[x].size());
            for(int j = i+1;j<v.size();j++){
                ll y = v[j];
                vv(ll) &v1 = m[x];
                vv(ll) &v2 = m[y];
                for(int i1 = 0;i1 <v1.size();i1++){
                    for(int i2 = i1+1;i2<v1.size();i2++){
                        int ind1 = v1[i1];
                        int ind2 = v1[i2];
                        ll c1 = (v2.end()-lower_bound(all(v2), ind1));
                        ll c2 = (v2.end()-lower_bound(all(v2), ind2));
                        ans += ((c1-c2)*c2);
                    }
                }
            }
        }
        cout << ans << endl;

    }

    return 0;
}


#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;
int a[3030];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    while(t--){

        cin>>n;
        vector<int> v(n*n+n+1);
        for(auto p:v)p=0;
        rep(i,1,n){
            cin>>a[i];
        }
        ll ans=0;
        per(j,n,1){
            int k=j+1;
            rep(l,k+1,n){
                v[a[k]*n+a[l]]++;
            }
            rep(i,1,j-1){
                ans+=v[a[i]*n+a[j]];
            }
        }
        cout<<ans<<"\n";

    }

    return 0;
}


#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;
int a[3030];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    while(t--){

        cin>>n;
        vector<int> v(n*n);
        fill(v.begin(),v.end(),0);
        rep(i,1,n){
            cin>>a[i];
        }
        ll ans=0;
        per(j,n,1){
            int k=j+1;
            rep(l,k+1,n){
                v[a[k]*n+a[l]]++;
            }
            rep(i,1,j-1){
                ans+=v[a[i]*n+a[j]];
            }
        }
        cout<<ans<<"\n";

    }

    return 0;
}


#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;
int a[3030];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    while(t--){

        cin>>n;
        vector<int> v[n+10];
        rep(i,1,n){
            cin>>a[i];
            v[a[i]].push_back(i);
        }
        ll ans=0;
        rep(i,1,n)if(v[i].size()>=4){
            ll val=v[i].size();
            ans+=val*(val-1)*(val-2)*(val-3)/24;
        }
        rep(i,1,n){
            if(v[i].size()<2)continue;
            rep(j,1,n){
                if(i==j)continue;
                if(v[j].size()<2)continue;
                ll si=1,sj=0;
                while(si<v[i].size()&&sj<v[j].size()){
                    int pj=sj;
                    while(sj<v[j].size()&&v[sj]<=v[si])++sj;
                    ans+=(v[i].size()-si)*(sj-pj)*(v[j].size()-sj);
//                    cout<<v[i].size()-si<<" "<<(sj-pj)<<" "<<v[j].size()-sj<<endl;
					++si;
                }
            }

        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;
int a[3030];
vector<int> mp[3030];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        rep(i,1,n)mp[i].clear();
        rep(i,1,n)cin>>a[i],mp[a[i]].push_back(i);
        ll ans=0;

        rep(i,1,n){
            rep(j,i,n){
                if(i==j){
                    if(mp[i].size()<4)continue;
                    ll v=mp[i].size();
                    ans+=v*(v-1)*(v-2)*(v-3)/24;
                }
                else{
                    ll v1=mp[i].size(),v2=mp[j].size();
                    if(v1<2||v2<2)continue;
                    ans+=v1*(v1-1)*v2*(v2-1)/4;
                    ll s1=0,s2=0;
//                    while(s1<v1&&s2<v2){
//                        while(s1<v1&&mp[i][s1]<mp[j][s2])++s1;
//                        ++s2;
//                        if(s1>0)cout<<s1<<' '<<s2<<' '<<v1<<' '<<v2<<endl,ans-=s1*(s1-1)*(v2-s2+1)/2;
//
//                    }
                    s1=0,s2=0;
                    while(s1<v1&&s2<v2){
                        while(s2<v2&&mp[j][s2]<mp[i][s1])++s2;
                        ++s1;
                        if(s2>0)ans-=s2*(s2-1)*(v1-s1+1)/2;

                    }

                }
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;
int a[3030];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    while(t--){

        cin>>n;
        vector<int> v(n*n);
        for(auto p:v)p=0;
        rep(i,1,n){
            cin>>a[i];
        }
        ll ans=0;
        per(j,n,1){
            int k=j+1;
            rep(l,k+1,n){
                v[a[k]*n+a[l]]++;
            }
            rep(i,1,j-1){
                ans+=v[a[i]*n+a[j]];
            }
        }
        cout<<ans<<"\n";

    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int num[100000+5];
int vis[100000+5];
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
		int ans = 0;
		for (int i = 1; i <= n; i++) {
            scanf("%d", &num[i]);
        }
        for (int i = 1; i <= n; i++) {
			int sum = 0;
            memset(vis, 0, sizeof(vis));
            for (int j = i + 1; j <= n; j++)
                vis[num[j]]++;
            for (int j = i - 1; j > 0; j--) {
				if (num[i] == num[j]) {
					ans += sum;
				}
				sum+=vis[num[j]];
            }
        }
		printf("%d\n", ans);
    }
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int num[5000];
int vis[5000];
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
		int ans = 0;
		for (int i = 1; i <= n; i++) {
            scanf("%d", &num[i]);
        }
        for (int i = 1; i <= n; i++) {
			int sum = 0;
            memset(vis, 0, sizeof(vis));
            for (int j = i + 1; j <= n; j++)
                vis[num[j]]++;
            for (int j = i - 1; j > 0; j--) {
				if (num[i] == num[j]) {
					ans += sum;
				}
				sum+=vis[num[j]];
            }
        }
		printf("%d", ans);
    }
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int num[100000+5];
int vis[100000+5];
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
            scanf("%d", &num[i]);
        }
        for (int i = 1; i <= n; i++) {
			ll sum = 0;
            memset(vis, 0, sizeof(vis));
            for (int j = i + 1; j <= n; j++)
                vis[num[j]]++;
            for (int j = i - 1; j > 0; j--) {
				if (num[i] == num[j]) {
					ans += sum;
				}
				sum+=vis[num[j]];
            }
        }
		printf("%d\n", ans);
    }
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int num[100000+5];
int vis[100000+5];
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
            scanf("%d", &num[i]);
        }
        for (int i = 1; i <= n; i++) {
			ll sum = 0;
            memset(vis, 0, sizeof(vis));
            for (int j = i + 1; j <= n; j++)
                vis[num[j]]++;
            for (int j = i - 1; j > 0; j--) {
				if (num[i] == num[j]) {
					ans += sum;
				}
				sum+=vis[num[j]];
            }
        }
		printf("%lld\n", ans);
    }
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int num[5000];
int vis[5000];
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
		int ans = 0;
		for (int i = 1; i <= n; i++) {
            scanf("%d", &num[i]);
        }
        for (int i = 1; i <= n; i++) {
			int sum = 0;
            memset(vis, 0, sizeof(vis));
            for (int j = i + 1; j <= n; j++)
                vis[num[j]]++;
            for (int j = i - 1; j > 0; j--) {
				if (num[i] == num[j]) {
					ans += sum;
				}
				sum+=vis[num[j]];
            }
        }
		printf("%d\n", ans);
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	// map<string,int> m;

	cin>>t;
	while(t--){
		cin>>n;
		std::vector<int> m((n*n + 2*n), 0);
		int *a = new int[n+1]{0};
		for(int i=1;i<=n;++i){
			cin>>a[i];
		}

		int ans = 0;

		for(int j=n;j>=1;--j){
			int k = j+1;
			for(int l=k+1;l<=n;++l){
				// string key = to_string(a[k]) + "|" + to_string(a[l]);
				int key = a[k]*n + a[l];
				m[key]++;
			}
			for(int i=1;i<j;++i){
				// string key = to_string(a[i]) + "|" + to_string(a[j]);
				int key = a[i]*n + a[j];
				ans += m[key];
			}
		}
		// for(auto i:m){
		// 	cout<<i.first<<" "<<i.second<<endl;
		// }
		cout<<ans<<endl;
		m.clear();
	}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	// map<string,int> m;

	cin>>t;
	while(t--){
		cin>>n;
		std::vector<int> m((n*n + n), 0);
		int *a = new int[n+1]{0};
		for(int i=1;i<=n;++i){
			cin>>a[i];
		}

		int ans = 0;

		for(int j=n;j>=1;--j){
			int k = j+1;
			for(int l=k+1;l<=n;++l){
				// string key = to_string(a[k]) + "|" + to_string(a[l]);
				int key = a[k]*n + a[l];
				m[key]++;
			}
			for(int i=1;i<j;++i){
				// string key = to_string(a[i]) + "|" + to_string(a[j]);
				int key = a[i]*n + a[j];
				ans += m[key];
			}
		}
		// for(auto i:m){
		// 	cout<<i.first<<" "<<i.second<<endl;
		// }
		cout<<ans<<endl;
		m.clear();
	}
return 0;
}


 #include<bits/stdc++.h>
 using namespace std;
 #define int long long int

 int32_t main()
 {
 	ios_base::sync_with_stdio(false);
 	cin.tie(0);
 	cout.tie(0);
 	int t;
 	int n;
 	cin>>t;
 	map<int,int> m;
 	vector<int> v;
 	while(t--){
 		cin>>n;
 		int count = 0;

 		int *a = new int[n]{0};

 		for(int i=0;i<n;++i){
 			cin>>a[i];
 			m[a[i]]++;
 		}

 		std::vector<int> v;
 		int ans = 0;
 		for(auto i:m){
 			v.push_back(i.second);
 		}
 		sort(v.begin(),v.end());
 		int n = v.size();
 		if(n > 1){
 			ans = min(v[n-1], v[n-2]);
 		}else{
	 		ans = v[n-1];
	 	}
 		cout<<ans<<endl;
 		m.clear();
 	}

 return 0;
 }


#include<bits/stdc++.h>
using namespace std;
#define int long long int

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	map<string,int> m;
	cin>>t;
	while(t--){
		cin>>n;
		int *a = new int[n+1]{0};
		for(int i=1;i<=n;++i){
			cin>>a[i];
		}

		int ans = 0;

		for(int j=n;j>=1;--j){
			int k = j+1;
			for(int l=k+1;l<=n;++l){
				string key = to_string(a[k]) + "|" + to_string(a[l]);
				m[key]++;
			}
			for(int i=1;i<j;++i){
				string key = to_string(a[i]) + "|" + to_string(a[j]);
				ans += m[key];
			}
		}
		// for(auto i:m){
		// 	cout<<i.first<<" "<<i.second<<endl;
		// }
		cout<<ans<<endl;
		m.clear();
	}
return 0;
}


 #include<bits/stdc++.h>
 using namespace std;
 #define int long long int

 int32_t main()
 {
 	ios_base::sync_with_stdio(false);
 	cin.tie(0);
 	cout.tie(0);
 	int t;
 	int n;
 	cin>>t;
 	while(t--){
 		cin>>n;
 		int count = 0;
 		int *a = new int[n]{0};
 		for(int i=0;i<n;++i){
 			cin>>a[i];
 		}
 		for(int i=0;i<n;++i){
 			for(int j=i+1;j<n;++j){
 				for(int k=j+1;k<n;++k){
 					for(int l=k+1;l<n;++l){
 						if(a[i] == a[k] && a[j] == a[l]){
 							count++;
 						}
 					}
 				}
 			}
 		}
 		cout<<count<<endl;
 	}

 return 0;
 }


#include<bits/stdc++.h>
using namespace std;
#define int long long int

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	// map<string,int> m;

	cin>>t;
	while(t--){
		cin>>n;
		std::vector<int> m(n*n, 0);
		int *a = new int[n+1]{0};
		for(int i=1;i<=n;++i){
			cin>>a[i];
		}

		int ans = 0;

		for(int j=n;j>=1;--j){
			int k = j+1;
			for(int l=k+1;l<=n;++l){
				// string key = to_string(a[k]) + "|" + to_string(a[l]);
				int key = a[k]*n + a[l];
				m[key]++;
			}
			for(int i=1;i<j;++i){
				// string key = to_string(a[i]) + "|" + to_string(a[j]);
				int key = a[i]*n + a[j];
				ans += m[key];
			}
		}
		// for(auto i:m){
		// 	cout<<i.first<<" "<<i.second<<endl;
		// }
		cout<<ans<<endl;
		m.clear();
	}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 3050;
typedef long long ll;
ll  F[4][MAXN][MAXN];
int N;
int A[MAXN];
int main()
{
//    freopen("1400D.INP","r",stdin);
//    freopen("1400D.OUT","w",stdout);
    faster
    int T;
    cin >> T;
    while( T-- )
    {
        cin >> N;
        int maxval = 0;
        FOR(i, 1, N) { cin >> A[i]; maxval = max( A[i] , maxval ); }
        FOR(i, 1, 3) FOR(j, 1, N) FOR(k, 1, maxval) F[i][j][k] = 0;
        FOR(i, 1, N)
        {
         ///   cout << 1 << endl;
             FOR(j, i + 1, N) { F[1][i][ A[j] ]++;  }
        ///     cout << endl;
        }
        ///cout << F[1][1][2] << endl;
        FOR(k, 2, 3)
        {
            FOR(i, 1, N)
            {
               FOR(j, i + 1 , N)
               {
                   F[k][i][ A[j] ] += F[k-1][j][ A[i] ];
               }
            }
        }
        ll ans = 0;
        FOR(i, 1, N) FOR(j, 1, maxval) ans += F[3][i][j];
        cout << ans << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 3005;
typedef long long ll;
int  F[4][MAXN][MAXN];
int N;
int A[MAXN];
int main()
{
//    freopen("1400D.INP","r",stdin);
//    freopen("1400D.OUT","w",stdout);
    faster
    int T;
    cin >> T;
    while( T-- )
    {
        cin >> N;
        int maxval = 0;
        FOR(i, 1, N) { cin >> A[i]; maxval = max( A[i] , maxval ); }
        FOR(i, 1, 3) FOR(j, 1, N) FOR(k, 1, maxval) F[i][j][k] = 0;
        FOR(i, 1, N)
        {
         ///   cout << 1 << endl;
             FOR(j, i + 1, N) { F[1][i][ A[j] ]++;  }
        ///     cout << endl;
        }
        ///cout << F[1][1][2] << endl;
        FOR(k, 2, 3)
        {
            FOR(i, 1, N)
            {
               FOR(j, i + 1 , N)
               {
                   F[k][i][ A[j] ] += F[k-1][j][ A[i] ];
               }
            }
        }
        int ans = 0;
        FOR(i, 1, N) FOR(j, 1, maxval) ans += F[3][i][j];
        cout << ans << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 3005;
typedef long long ll;
ll  F[3][MAXN][MAXN];
int N;
int A[MAXN];
int main()
{
//    freopen("1400D.INP","r",stdin);
//    freopen("1400D.OUT","w",stdout);
    faster
    int T;
    cin >> T;
    while( T-- )
    {
        cin >> N;
        int maxval = 0;
        FOR(i, 1, N) { cin >> A[i]; maxval = max( A[i] , maxval ); }
        FOR(i, 0, 2) FOR(j, 1, N) FOR(k, 1, maxval) F[i][j][k] = 0;
        FOR(i, 1, N)
        {
         ///   cout << 1 << endl;
             FOR(j, i + 1, N) { F[0][i][ A[j] ]++;  }
        ///     cout << endl;
        }
        //cout << F[1][1][2] << endl;
        FOR(k, 1, 2)
        {
            FOR(i, 1, N)
            {
               FOR(j, i + 1 , N)
               {
                   F[k][i][ A[j] ] += F[k-1][j][ A[i] ];
               }
            }
        }
        ll ans = 0;
        FOR(i, 1, N) FOR(j, 1, maxval) ans += F[2][i][j];
        cout << ans << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 3005;
typedef long long ll;
int  F[3][MAXN][MAXN];
int N;
int A[MAXN];
int main()
{
//    freopen("1400D.INP","r",stdin);
//    freopen("1400D.OUT","w",stdout);
    faster
    int T;
    cin >> T;
    while( T-- )
    {
        cin >> N;
        int maxval = 0;
        FOR(i, 1, N) { cin >> A[i]; maxval = max( A[i] , maxval ); }
        FOR(i, 0, 2) FOR(j, 1, N) FOR(k, 1, maxval) F[i][j][k] = 0;
        FOR(i, 1, N)
        {
         ///   cout << 1 << endl;
             FOR(j, i + 1, N) { F[0][i][ A[j] ]++;  }
        ///     cout << endl;
        }
        //cout << F[1][1][2] << endl;
        FOR(k, 1, 2)
        {
            FOR(i, 1, N)
            {
               FOR(j, i + 1 , N)
               {
                   F[k][i][ A[j] ] += F[k-1][j][ A[i] ];
               }
            }
        }
        int ans = 0;
        FOR(i, 1, N) FOR(j, 1, maxval) ans += F[2][i][j];
        cout << ans << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 3005;
typedef long long ll;
ll  F[4][MAXN][MAXN];
int N;
int A[MAXN];
int main()
{
//    freopen("1400D.INP","r",stdin);
//    freopen("1400D.OUT","w",stdout);
    faster
    int T;
    cin >> T;
    while( T-- )
    {
        cin >> N;
        int maxval = 0;
        FOR(i, 1, N) { cin >> A[i]; maxval = max( A[i] , maxval ); }
        FOR(i, 1, 3) FOR(j, 1, N) FOR(k, 1, maxval) F[i][j][k] = 0;
        FOR(i, 1, N)
        {
         ///   cout << 1 << endl;
             FOR(j, i + 1, N) { F[1][i][ A[j] ]++;  }
        ///     cout << endl;
        }
        ///cout << F[1][1][2] << endl;
        FOR(k, 2, 3)
        {
            FOR(i, 1, N)
            {
               FOR(j, i + 1 , N)
               {
                   F[k][i][ A[j] ] += F[k-1][j][ A[i] ];
               }
            }
        }
        ll ans = 0;
        FOR(i, 1, N) FOR(j, 1, maxval) ans += F[3][i][j];
        cout << ans << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ft first
#define sd second

#define v vector<ll>
#define vecv vector<v>
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))

#define err() cout<<"==================================\n";
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n"
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n"

#define pb push_back
#define fr(i, a, b) for(ll i=a; i<b; i++)
#define rf(i, a, b) for(ll i=a; i>=b; i--)

#define MOD 1e9 + 7
#define INF 9e18

void solve()
{
	ll n, ans=0;
	cin>>n;
	v a(n+1);
	fr(i, 1, n+1)
		cin>>a[i];
	bool fla=true;
	fr(i, 1, n+1)
		if(a[i]!=a[1]) fla=false;

	if(fla)
	{
		cout<<(n*(n-1)*(n-2)*(n-3))/24<<"\n";
		return;
	}
	vector<vector<int>> number(n+1, vector<int>(n+1, 0)); //presums
	vector<pair<int, int>> pa; //all pairs i, k
	fr(i, 1, n+1)
	{
		fr(j, 1, n+1)
			if(a[j]==i) number[i][j]=number[i][j-1]+1;
			else number[i][j]=number[i][j-1];
	}
	fr(i, 1, n+1)
	{
		fr(j, i+1, n+1)
			if(a[i]==a[j]) pa.pb(make_pair(i, j));
	}
	for(auto p: pa)
	{
		fr(i, 1, n+1)
		{
			if(i==a[p.ft]) continue;
			ans+=(number[i][p.sd]-number[i][p.ft])*(number[i][n]-number[i][p.sd]);
		}
	}
	fr(i, 1, n+1)
	{
		ll t=number[i][n];
		if(t>=4)
			ans+=(t*(t-1)*(t-2)*(t-3))/24;
	}
	cout<<ans;
	cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(0);
    //freopen("input.txt", "r", stdin);
    ll t=1; cin>>t;
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ft first
#define sd second

#define v vector<ll>
#define vecv vector<v>
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))

#define err() cout<<"==================================\n";
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n"
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n"

#define pb push_back
#define fr(i, a, b) for(ll i=a; i<b; i++)
#define rf(i, a, b) for(ll i=a; i>=b; i--)

#define MOD 1e9 + 7
#define INF 9e18

void solve()
{
	ll n, ans=0;
	cin>>n;
	v a(n+1);
	fr(i, 1, n+1)
		cin>>a[i];

	vector<vector<int>> number(n+1, vector<int>(n+1, 0)); //presums
	vector<pair<int, int>> pa; //all pairs i, k
	fr(i, 1, n+1)
	{
		fr(j, 1, n+1)
			if(a[j]==i) number[i][j]=number[i][j-1]+1;
			else number[i][j]=number[i][j-1];
	}
	fr(i, 1, n+1)
	{
		fr(j, i+1, n+1)
			if(a[i]==a[j]) pa.pb(make_pair(i, j));
	}
	for(auto p: pa)
	{
		fr(i, 1, n+1)
		{
			if(i==a[p.ft]) continue;
			ans+=(number[i][p.sd]-number[i][p.ft])*(number[i][n]-number[i][p.sd]);
		}
	}
	fr(i, 1, n+1)
	{
		ll t=number[i][n];
		if(t>=4)
			ans+=(t*(t-1)*(t-2)*(t-3))/24;
	}
	cout<<ans;
	cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(0);
    //freopen("input.txt", "r", stdin);
    ll t=1; cin>>t;
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ft first
#define sd second

#define v vector<ll>
#define vecv vector<v>
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))

#define err() cout<<"==================================\n";
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n"
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n"

#define pb push_back
#define fr(i, a, b) for(ll i=a; i<b; i++)
#define rf(i, a, b) for(ll i=a; i>=b; i--)

#define MOD 1e9 + 7
#define INF 9e18

void solve()
{
	ll n, ans=0;
	cin>>n;
	v a(n+1);
	fr(i, 1, n+1)
		cin>>a[i];

	vector<vector<int>> number(n+1, v(n+1, 0)); //presums
	vector<pair<int, int>> pa; //all pairs i, k
	fr(i, 1, n+1)
	{
		fr(j, 1, n+1)
			if(a[j]==i) number[i][j]=number[i][j-1]+1;
			else number[i][j]=number[i][j-1];
	}
	fr(i, 1, n+1)
	{
		fr(j, i+1, n+1)
			if(a[i]==a[j]) pa.pb(make_pair(i, j));
	}
	for(auto p: pa)
	{
		fr(i, 1, n+1)
		{
			if(i==a[p.ft]) continue;
			ans+=(number[i][p.sd]-number[i][p.ft])*(number[i][n]-number[i][p.sd]);
		}
	}
	fr(i, 1, n+1)
	{
		ll t=number[i][n];
		if(t>=4)
			ans+=(t*(t-1)*(t-2)*(t-3))/24;
	}
	cout<<ans;
	cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(0);
    //freopen("input.txt", "r", stdin);
    ll t=1; cin>>t;
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ft first
#define sd second

#define v vector<ll>
#define vecv vector<v>
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))

#define err() cout<<"==================================\n";
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n"
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n"

#define pb push_back
#define fr(i, a, b) for(ll i=a; i<b; i++)
#define rf(i, a, b) for(ll i=a; i>=b; i--)

#define MOD 1e9 + 7
#define INF 9e18

void solve()
{
	ll n, ans=0;
	cin>>n;
	v a(n+1);
	fr(i, 1, n+1)
		cin>>a[i];
	bool fla=true
	fr(i, 0, n)
		fla&=(a[i]==a[0]);
	if(fla)
	{
		cout<<(n*(n-1)*(n-2)*(n-3))/24<<"\n";
		return;
	}
	vector<vector<int>> number(n+1, vector<int>(n+1, 0)); //presums
	vector<pair<int, int>> pa; //all pairs i, k
	fr(i, 1, n+1)
	{
		fr(j, 1, n+1)
			if(a[j]==i) number[i][j]=number[i][j-1]+1;
			else number[i][j]=number[i][j-1];
	}
	fr(i, 1, n+1)
	{
		fr(j, i+1, n+1)
			if(a[i]==a[j]) pa.pb(make_pair(i, j));
	}
	for(auto p: pa)
	{
		fr(i, 1, n+1)
		{
			if(i==a[p.ft]) continue;
			ans+=(number[i][p.sd]-number[i][p.ft])*(number[i][n]-number[i][p.sd]);
		}
	}
	fr(i, 1, n+1)
	{
		ll t=number[i][n];
		if(t>=4)
			ans+=(t*(t-1)*(t-2)*(t-3))/24;
	}
	cout<<ans;
	cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(0);
    //freopen("input.txt", "r", stdin);
    ll t=1; cin>>t;
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ft first
#define sd second

#define v vector<ll>
#define vecv vector<v>
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))

#define err() cout<<"==================================\n";
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n"
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n"

#define pb push_back
#define fr(i, a, b) for(ll i=a; i<b; i++)
#define rf(i, a, b) for(ll i=a; i>=b; i--)

#define MOD 1e9 + 7
#define INF 9e18

void solve()
{
	ll n, ans=0;
	cin>>n;
	v a(n+1);
	fr(i, 1, n+1)
		cin>>a[i];

	vecv number(n+1, v(n+1, 0)); //presums
	vector<pair<ll, ll>> pa; //all pairs i, k
	fr(i, 1, n+1)
	{
		fr(j, 1, n+1)
			if(a[j]==i) number[i][j]=number[i][j-1]+1;
			else number[i][j]=number[i][j-1];
	}
	fr(i, 1, n+1)
	{
		fr(j, i+1, n+1)
			if(a[i]==a[j]) pa.pb(make_pair(i, j));
	}
	for(auto p: pa)
	{
		fr(i, 1, n+1)
		{
			if(i==a[p.ft]) continue;
			ans+=(number[i][p.sd]-number[i][p.ft])*(number[i][n]-number[i][p.sd]);
		}
	}
	fr(i, 1, n+1)
	{
		ll t=number[i][n];
		if(t>=4)
			ans+=(t*(t-1)*(t-2)*(t-3))/24;
	}
	cout<<ans;
	cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(0);
    //freopen("input.txt", "r", stdin);
    ll t=1; cin>>t;
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ft first
#define sd second

#define v vector<ll>
#define vecv vector<v>
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))

#define err() cout<<"==================================\n";
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n"
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n"

#define pb push_back
#define fr(i, a, b) for(ll i=a; i<b; i++)
#define rf(i, a, b) for(ll i=a; i>=b; i--)

#define MOD 1e9 + 7
#define INF 9e18

void solve()
{
	ll n, ans=0;
	cin>>n;
	v a(n+1);
	fr(i, 1, n+1)
		cin>>a[i];
	vector<vector<int>> number(n+1, vector<int>(n+1, 0)); //presums
	fr(i, 1, n+1)
	{
		fr(j, 1, n+1)
			if(a[j]==i) number[i][j]=number[i][j-1]+1;
			else number[i][j]=number[i][j-1];
	}
	fr(i, 1, n+1)
	{
		fr(j, i+1, n+1)
			if(a[i]!=a[j])
				ans+=number[a[j]][i]*(number[a[i]][n]-number[a[i]][j]);
	}
	fr(i, 1, n+1)
	{
		ll t=number[i][n];
		if(t>=4)
			ans+=(t*(t-1)*(t-2)*(t-3))/24;
	}
	cout<<ans;
	cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(0);
    //freopen("input.txt", "r", stdin);
    ll t=1; cin>>t;
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ft first
#define sd second

#define v vector<ll>
#define vecv vector<v>
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))

#define err() cout<<"==================================\n";
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n"
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n"

#define pb push_back
#define fr(i, a, b) for(ll i=a; i<b; i++)
#define rf(i, a, b) for(ll i=a; i>=b; i--)

#define MOD 1e9 + 7
#define INF 9e18

void solve()
{
	ll n, ans=0;
	cin>>n;
	v a(n+1);
	fr(i, 1, n+1)
		cin>>a[i];

	vecv number(n+1, v(n+1, 0)); //presums
	vector<pair<ll, ll>> pa; //all pairs i, k
	fr(i, 1, n+1)
	{
		fr(j, 1, n+1)
			if(a[j]==i) number[i][j]=number[i][j-1]+1;
			else number[i][j]=number[i][j-1];
	}
	fr(i, 1, n+1)
	{
		fr(j, i+1, n+1)
			if(a[i]==a[j]) pa.pb(make_pair(i, j));
	}
	for(auto p: pa)
	{
		fr(i, 1, n+1)
		{
			if(i==a[p.ft]) continue;
			ans+=(number[i][p.sd]-number[i][p.ft])*(number[i][n]-number[i][p.sd]);
		}
	}
	fr(i, 1, n)
	{
		ll t=number[i][n];
		if(t>=4)
			ans+=(t*(t-1)*(t-2)*(t-3))/24;
	}
	cout<<ans;
	cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(0);
    //freopen("input.txt", "r", stdin);
    ll t=1; cin>>t;
    while(t--) solve();
    return 0;
}


/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld             long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);
    #endif
    ll t = 1;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll> v(n+1,0);
        vector<ll> cnt(n*n+5,0);
        for(ll i=1;i<=n;i++)
            cin>>v[i];
        ll ans = 0;
        for(ll i=1;i<=n-1;i++)
        {
            for(ll j=i-1;j>=1;j--)
                cnt[n*v[j]+v[i]]++;
            for(ll j=i+2;j<=n;j++)
                ans+=cnt[n*(v[i+1])+v[j]];
        }
        cout<<ans<<'\n';
    }

    time
    return 0;
}


/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const ll N = 3005;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll x;
		vector<ll> v[n+5];
		ll pre[n+5][n+5];
		memset(pre,0,sizeof(pre));
		vector<ll> a;
		ll jinx = 1;
		vector<ll> vis(n+1,0);
		for(ll i=1;i<=n;i++)
		{
			cin>>x;
			if(vis[x]==0)
			{
				vis[x] = jinx;
				pre[i][jinx]++;
				a.push_back(x);
				v[jinx].push_back(i);
				jinx++;
			}
			else
			{
				pre[i][vis[x]]++;
				v[vis[x]].push_back(i);
			}
			for(ll j=1;j<=jinx;j++)
				pre[i][j]+=pre[i-1][j];
		}
		for(ll j=1;j<=jinx;j++)
			pre[n+1][j]+=pre[n][j];
		ll ans = 0;
		ll y;
		ll temp = 0;
		for(ll i=1;i<=jinx;i++)
		{
			temp = 0;
			for(ll j=0;j<v[i].size();j++)
			{
				for(ll k=j+1;k<v[i].size();k++)
				{
					x = v[i][j];
					y = v[i][k];
					for(ll l=1;l<=jinx;l++)
					{
						if(l!=i)
						{
							// cout<<x<<" "<<y<<endl;
							// cout<<(pre[y-1][l]-pre[x][l])<<" || "<<(pre[n+1][l]-pre[y][l])<<endl;
							ans += (pre[y-1][l]-pre[x][l])*(pre[n+1][l]-pre[y][l]);
							ans += pre[x-1][l]*(pre[y-1][l]-pre[x][l]);
						}
						else
						{
							temp += (pre[y-1][l]-pre[x][l])*(pre[n+1][l]-pre[y][l]);
							temp += pre[x-1][l]*(pre[y-1][l]-pre[x][l]);
						}
					}
				}
			}
			ans += temp;
		}
		cout<<ans/2<<'\n';

	}

	time
	return 0;
}


/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const ll N = 3005;
ll pre[N][N];
vector<ll> v[N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll x;
		for(int i=1;i<=n;i++)
		{
			v[i].clear();
			for(int j=1;j<=n+1;j++)
				pre[i][j] = 0;
		}
		vector<ll> a;
		ll jinx = 1;
		vector<ll> vis(N,0);
		for(ll i=1;i<=n;i++)
		{
			cin>>x;
			if(vis[x]==0)
			{
				vis[x] = jinx;
				pre[i][jinx]++;
				a.push_back(x);
				v[jinx].push_back(i);
				jinx++;
			}
			else
			{
				pre[i][vis[x]]++;
				v[vis[x]].push_back(i);
			}
			for(ll j=1;j<=jinx;j++)
				pre[i][j]+=pre[i-1][j];
		}
		for(ll j=1;j<=jinx;j++)
			pre[n+1][j]+=pre[n][j];
		ll ans = 0;
		ll y;
		ll temp = 0;
		for(ll i=1;i<=jinx;i++)
		{
			temp = 0;
			for(ll j=0;j<v[i].size();j++)
			{
				for(ll k=j+1;k<v[i].size();k++)
				{
					x = v[i][j];
					y = v[i][k];
					for(ll l=1;l<=jinx;l++)
					{
						if(l!=i)
						{
							// cout<<x<<" "<<y<<endl;
							// cout<<(pre[y-1][l]-pre[x][l])<<" || "<<(pre[n+1][l]-pre[y][l])<<endl;
							ans += (pre[y-1][l]-pre[x][l])*(pre[n+1][l]-pre[y][l]);
							ans += pre[x-1][l]*(pre[y-1][l]-pre[x][l]);
						}
						else
						{
							temp += (pre[y-1][l]-pre[x][l])*(pre[n+1][l]-pre[y][l]);
							temp += pre[x-1][l]*(pre[y-1][l]-pre[x][l]);
						}
					}
				}
			}
			ans += temp;
		}
		cout<<ans/2<<'\n';

	}

	time
	return 0;
}


/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const ll N = 3005;
ll pre[N][N];
vector<ll> v[N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll x;
		for(int i=1;i<N;i++)
		{
			v[i].clear();
			for(int j=1;j<N;j++)
				pre[i][j] = 0;
		}
		vector<ll> a;
		ll jinx = 1;
		vector<ll> vis(N,0);
		for(ll i=1;i<=n;i++)
		{
			cin>>x;
			if(vis[x]==0)
			{
				vis[x] = jinx;
				pre[i][jinx]++;
				a.push_back(x);
				v[jinx].push_back(i);
				jinx++;
			}
			else
			{
				pre[i][vis[x]]++;
				v[vis[x]].push_back(i);
			}
			for(ll j=1;j<=jinx;j++)
				pre[i][j]+=pre[i-1][j];
		}
		for(ll j=1;j<=jinx;j++)
			pre[n+1][j]+=pre[n][j];
		ll ans = 0;
		ll y;
		ll temp = 0;
		for(ll i=1;i<=jinx;i++)
		{
			temp = 0;
			for(ll j=0;j<v[i].size();j++)
			{
				for(ll k=j+1;k<v[i].size();k++)
				{
					x = v[i][j];
					y = v[i][k];
					for(ll l=1;l<=jinx;l++)
					{
						if(l!=i)
						{
							// cout<<x<<" "<<y<<endl;
							// cout<<(pre[y-1][l]-pre[x][l])<<" || "<<(pre[n+1][l]-pre[y][l])<<endl;
							ans += (pre[y-1][l]-pre[x][l])*(pre[n+1][l]-pre[y][l]);
							ans += pre[x-1][l]*(pre[y-1][l]-pre[x][l]);
						}
						else
						{
							temp += (pre[y-1][l]-pre[x][l])*(pre[n+1][l]-pre[y][l]);
							temp += pre[x-1][l]*(pre[y-1][l]-pre[x][l]);
						}
					}
				}
			}
			ans += temp;
		}
		cout<<ans/2<<'\n';

	}

	time
	return 0;
}


/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const ll N = 3005;
ll pre[N][N];
vector<ll> v[N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll x;
		for(int i=1;i<=n;i++)
		{
			v[i].clear();
			for(int j=1;j<N;j++)
				pre[i][j] = 0;
		}
		vector<ll> a;
		ll jinx = 1;
		vector<ll> vis(N,0);
		for(ll i=1;i<=n;i++)
		{
			cin>>x;
			if(vis[x]==0)
			{
				vis[x] = jinx;
				pre[i][jinx]++;
				a.push_back(x);
				v[jinx].push_back(i);
				jinx++;
			}
			else
			{
				pre[i][vis[x]]++;
				v[vis[x]].push_back(i);
			}
			for(ll j=1;j<=jinx;j++)
				pre[i][j]+=pre[i-1][j];
		}
		for(ll j=1;j<=jinx;j++)
			pre[n+1][j]+=pre[n][j];
		ll ans = 0;
		ll y;
		ll temp = 0;
		for(ll i=1;i<=jinx;i++)
		{
			temp = 0;
			for(ll j=0;j<v[i].size();j++)
			{
				for(ll k=j+1;k<v[i].size();k++)
				{
					x = v[i][j];
					y = v[i][k];
					for(ll l=1;l<=jinx;l++)
					{
						if(l!=i)
						{
							// cout<<x<<" "<<y<<endl;
							// cout<<(pre[y-1][l]-pre[x][l])<<" || "<<(pre[n+1][l]-pre[y][l])<<endl;
							ans += (pre[y-1][l]-pre[x][l])*(pre[n+1][l]-pre[y][l]);
							ans += pre[x-1][l]*(pre[y-1][l]-pre[x][l]);
						}
						else
						{
							temp += (pre[y-1][l]-pre[x][l])*(pre[n+1][l]-pre[y][l]);
							temp += pre[x-1][l]*(pre[y-1][l]-pre[x][l]);
						}
					}
				}
			}
			ans += temp/3LL;
		}
		cout<<ans/2<<'\n';

	}

	time
	return 0;
}


/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld             long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);
    #endif
    ll t = 1;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll> v(n+1,0);
        vector<ll> cnt(n*n+5,0);
        ll cur = 1;
        vector<ll> vis(n+1,0);
        for(ll i=1;i<=n;i++)
        {
            cin>>v[i];
            if(vis[v[i]]==0)
            {
                vis[v[i]] = cur;
                cur++;
            }
            v[i] = vis[v[i]];
        }
        ll ans = 0;
        for(ll i=1;i<=n-1;i++)
        {
            for(ll j=i-1;j>=1;j--)
                cnt[n*v[j]+v[i]]++;
            for(ll j=i+2;j<=n;j++)
                ans+=cnt[n*v[i+1]+v[j]];
        }
        cout<<ans<<'\n';
    }

    time
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define vvb vector<vb>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

template<typename T>
bool compare(const T &a,const T &b){
    return a.S<b.F;
}

void solve(){
	int n;
	cin >> n;

	vi a(n);
	for(int& x : a)cin >> x;

	map<pii, vi> mp, mp2;
	for(int i=0 ; i<n ; ++i){
		for(int j=i+1 ; j<n ; ++j){
			mp[{a[i], a[j]}].pb(i);
			mp2[{a[i], a[j]}].pb(j);
		}
	}

	ll cnt=0;
	for(auto it : mp2){
		pii p = it.F;
		for(int& x : it.S){
			int pos = upper_bound(all(mp[p]), x) - mp[p].begin();
			cnt += (it.S.size() - pos);
		}
	}

	cout << cnt << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define vvb vector<vb>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n;
	cin >> n;

	vi a(n);
	for(int& x : a)cin >> x;

	map<int, vi> mp;
	for(int i=0 ; i<n ; ++i){
		mp[a[i]].pb(i);
	}

	int cnt=0;
	for(int i=0 ; i<n ; ++i){
		for(int j=i+1 ; j<n ; ++j){
			int one = a[i], two = a[j];
			int pos = upper_bound(all(mp[one]), j) - mp[one].begin();
			for(int ii=pos ; ii<mp[one].size() ; ++ii){
				pos = upper_bound(all(mp[two]), mp[one][ii]) - mp[two].begin();
				cnt += (mp[two].size() - pos);
			}
		}
	}

	cout << cnt << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define vvb vector<vb>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

template<typename T>
bool compare(const T &a,const T &b){
    return a.S<b.F;
}

void solve(){
	int n;
	cin >> n;

	vi a(n);
	for(int& x : a)cin >> x;

	map<pii, vi> mp, mp2;
	for(int i=0 ; i<n ; ++i){
		for(int j=i+1 ; j<n ; ++j){
			mp[{a[i], a[j]}].pb(i);
			mp2[{a[i], a[j]}].pb(j);
		}
	}

	int cnt=0;
	for(auto it : mp2){
		pii p = it.F;
		for(int& x : it.S){
			int pos = upper_bound(all(mp[p]), x) - mp[p].begin();
			cnt += (it.S.size() - pos);
		}
	}

	cout << cnt << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define vvb vector<vb>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

template<typename T>
bool compare(const T &a,const T &b){
    return a.S<b.F;
}

void solve(){
	int n;
	cin >> n;

	vi a(n);
	for(int& x : a)cin >> x, --x;

	vi l(n+1, 0);
	ll ans=0;
	for(int i=0 ; i<n ; ++i){
		vi r(n+1, 0);
		for(int j=i+1 ; j<n ; ++j)++r[a[j]];

		for(int j=i+1 ; j<n ; ++j){
			--r[a[j]];
			ans += l[a[j]] * r[a[i]];
		}

		++l[a[i]];
	}

	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define vvb vector<vb>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

template<typename T>
bool compare(const T &a,const T &b){
    return a.S<b.F;
}

void solve(){
	int n;
	cin >> n;

	vi a(n);
	for(int& x : a)cin >> x, --x;

	vi l(n, 0);
	int ans=0;
	for(int i=0 ; i<n ; ++i){
		vi r(n, 0);
		for(int j=i+1 ; j<n ; ++j)++r[a[j]];

		for(int j=i+1 ; j<n ; ++j){
			--r[a[j]];
			ans += l[a[j]] * r[a[i]];
		}

		++l[a[i]];
	}

	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define vvb vector<vb>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

template<typename T>
bool compare(const T &a,const T &b){
    return a.S<b.F;
}

void solve(){
	int n;
	cin >> n;

	vi a(n);
	for(int& x : a)cin >> x;

	map<pii, vpii> mp;
	for(int i=0 ; i<n ; ++i){
		for(int j=i+1 ; j<n ; ++j){
			mp[{a[i], a[j]}].pb({i, j});
		}
	}

	int cnt=0;
	for(auto it : mp){
		if(it.second.size() < 2)continue;
		for(pii p : it.S){
			auto itr = std::find_if( it.S.begin(), it.S.end(),
    		[&p](const std::pair<int, int>& element){ return element.first > p.S;} );
    		int pos = itr - it.S.begin();
			cnt += (it.second.size() - pos);
		}
	}

	cout << cnt << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define vvb vector<vb>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

template<typename T>
bool compare(const T &a,const T &b){
    return a.S<b.F;
}

void solve(){
	int n;
	cin >> n;

	vi a(n);
	for(int& x : a)cin >> x, --x;

	vi l(n, 0);
	int ans=0;
	for(int i=0 ; i<n ; ++i){
		vi r(n, 0);
		for(int j=i+2 ; j<n ; ++j)++r[a[j]];

		for(int j=i+1 ; j<n ; ++j){
			ans += l[a[j]] * r[a[i]];
			--r[a[j]];
		}

		++l[a[i]];
	}

	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(10);

	int tt=1;
	cin >> tt;

	while(tt--){
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;

long long int func(long long int arr[],long long int n)
{
    unordered_map<long long int,long long int>mp1;
    unordered_map<long long int,long long int>mp2;
    map<pair<long long int,long long int>,long long int>ans;

    mp1[arr[0]]++;
    mp2[arr[2]]++;

    long long int temp=0;
    for(auto x:mp1)
    {
        if(mp2.count(x.first))
        temp+=mp1[x.first]*mp2[x.first];
    }
    //cout<<temp;
    ans[{1,3}]=temp;

    for(long long int i=1;i<n;i++)
    {
        for(long long int j=i+3;j<n;j++)
        {
            temp+=mp1[arr[j-1]];
            mp2[arr[j-1]]++;
            ans[{i,j}]=temp;
        }
        mp1[arr[i]]++;
        mp2.clear();
        mp2[arr[i+2]]++;
        temp=0;

        for(auto x:mp1)
        {
            if(mp2.count(x.first))
            temp+=mp1[x.first]*mp2[x.first];
        }
        ans[{i+1,i+3}]=temp;
    }
    // for(int i=1;i<n;i++)
    // {
    //     for(int j=i+2;j<n;j++)
    //     {
    //         if(arr[i]==arr[j])
    //         ans[{i,j}]++;
    //     }
    // }
    long long int output=0;
    for(long long int i=1;i<n;i++)
    {
        for(long long int j=i+2;j<n;j++)
        {
            if(arr[i]==arr[j])
            {
                output+=ans[{i,j}];
            }
        }
    }
   // cout<<output;
    return output;
}
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        long long int n;
        cin>>n;
        long long int arr[n];
        for(long long int i=0;i<n;i++)
        cin>>arr[i];
        cout<<func(arr,n)<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

int func(int arr[],int n)
{
    unordered_map<int,int>mp1;
    unordered_map<int,int>mp2;
    unordered_map<pair<int,int>,int>ans;

    mp1[arr[0]]++;
    mp2[arr[2]]++;

    int temp=0;
    for(auto x:mp1)
    {
        if(mp2.count(x.first))
        temp+=mp1[x.first]*mp2[x.first];
    }
    ans[{1,3}]=temp;

    for(int i=1;i<n;i++)
    {
        for(int j=i+3;j<n;j++)
        {
            temp+=mp1[arr[j-1]];
            mp2[arr[j-1]]++;
            ans[{i,j}]=temp;
        }
        mp1[arr[i]]++;
        mp2.clear();
        mp2[arr[i+2]]++;
        temp=0;

        for(auto x:mp1)
        {
            if(mp2.count(x.first))
            temp+=mp1[x.first]*mp2[x.first];
        }
        ans[{i+1,i+3}]=temp;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=i+2;j<n;j++)
        {
            if(arr[i]==arr[j])
            ans[{i,j}]++;
        }
    }
    int output=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i+2;j<n;j++)
        {
            if(arr[i]==arr[j])
            {
                output+=ans[{i,j}];
            }
        }
    }
    return output;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++)
        cin>>arr[i];
        cout<<func(arr,n)<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

int func(int arr[],int n)
{
    unordered_map<int,int>mp1;
    unordered_map<int,int>mp2;
    map<pair<int,int>,int>ans;

    mp1[arr[0]]++;
    mp2[arr[2]]++;

    int temp=0;
    for(auto x:mp1)
    {
        if(mp2.count(x.first))
        temp+=mp1[x.first]*mp2[x.first];
    }
    //cout<<temp;
    ans[{1,3}]=temp;

    for(int i=1;i<n;i++)
    {
        for(int j=i+3;j<n;j++)
        {
            temp+=mp1[arr[j-1]];
            mp2[arr[j-1]]++;
            ans[{i,j}]=temp;
        }
        mp1[arr[i]]++;
        mp2.clear();
        mp2[arr[i+2]]++;
        temp=0;

        for(auto x:mp1)
        {
            if(mp2.count(x.first))
            temp+=mp1[x.first]*mp2[x.first];
        }
        ans[{i+1,i+3}]=temp;
    }
    // for(int i=1;i<n;i++)
    // {
    //     for(int j=i+2;j<n;j++)
    //     {
    //         if(arr[i]==arr[j])
    //         ans[{i,j}]++;
    //     }
    // }
    int output=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i+2;j<n;j++)
        {
            if(arr[i]==arr[j])
            {
                output+=ans[{i,j}];
            }
        }
    }
    //cout<<output;
    return output;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++)
        cin>>arr[i];
        cout<<func(arr,n)<<endl;
    }
}