题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4609
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///神仙的FFT模板
#define maxn 131072+5
const double pi=acos(-1.0);
struct cp{double a,b;cp operator +(const cp &o)const {return (cp){a+o.a,b+o.b};}cp operator -(const cp &o)const {return (cp){a-o.a,b-o.b};}cp operator *(const cp &o)const {return (cp){a*o.a-b*o.b,b*o.a+a*o.b};}cp operator *(const double &o)const {return (cp){a*o,b*o};}cp operator !() const{return (cp){a,-b};}
}w[maxn];
int pos[maxn];
void fft_init(int len){int j=0;while((1<<j)<len)j++;j--;for(int i=0;i<len;i++)pos[i]=pos[i>>1]>>1|((i&1)<<j);
}
void fft(cp *x,int len,int sta){for(int i=0;i<len;i++) if(i<pos[i])swap(x[i],x[pos[i]]);w[0]=(cp){1,0};for(unsigned i=2;i<=len;i<<=1){cp g=(cp){cos(2*pi/i),sin(2*pi/i)*sta};for(int j=i>>1;j>=0;j-=2)w[j]=w[j>>1];for(int j=1;j<i>>1;j+=2)w[j]=w[j-1]*g;for(int j=0;j<len;j+=i){cp *a=x+j,*b=a+(i>>1);for(int l=0;l<i>>1;l++){cp o=b[l]*w[l];b[l]=a[l]-o;a[l]=a[l]+o;}}}if(sta==-1)for(int i=0;i<len;i++)x[i].a/=len,x[i].b/=len;
}///1.5次DFT
cp x[maxn],y[maxn],z[maxn];
void FFT(ll *a,ll *b,int n,int m,ll *c){int len=1;while(len<(n+m)>>1)len<<=1;fft_init(len);for(int i=n/2;i<len;i++)x[i].a=x[i].b=0;for(int i=m/2;i<len;i++)y[i].a=y[i].b=0;for(int i=0;i<n;i++)(i&1?x[i>>1].b:x[i>>1].a)=a[i];for(int i=0;i<m;i++)(i&1?y[i>>1].b:y[i>>1].a)=b[i];fft(x,len,1),fft(y,len,1);for(int i=0;i<len/2;i++){int j=len-1&len-i;z[i]=x[i]*y[i]-(x[i]-!x[j])*(y[i]-!y[j])*(w[i]+(cp){1,0})*0.25;}for(int i=len/2;i<len;i++){int j=len-1&len-i;z[i]=x[i]*y[i]-(x[i]-!x[j])*(y[i]-!y[j])*((cp){1,0}-w[i^len>>1])*0.25;}fft(z,len,-1);for(int i=0;i<n+m;i++)if(i&1)c[i]=(ll)(z[i>>1].b+0.5);else c[i]=(ll)(z[i>>1].a+0.5);
}
int n,len,Max,a[maxn];
ll num[maxn<<1],sum[maxn<<1];///
int main(){int t;scanf("%d",&t);while(t--){scanf("%d",&n);mst(num,0),sum[0]=0,Max=0;///FFT数组rep(i,0,n){scanf("%d",&a[i]);num[a[i]]++;Max=max(Max,a[i]);}FFT(num,num,Max+1,Max+1,num);Max<<=1;rep(i,0,n) num[2*a[i]]--;rep(i,0,Max+1) num[i]>>=1;rep(i,1,Max+1) sum[i]=1LL*num[i]+sum[i-1];ll ans=0;rep(i,0,n){///对于特定的位置,用组合的知识去重ans+=sum[Max]-sum[a[i]];ans-=1LL*i*(n-i-1);ans-=1LL*(n-1);ans-=1LL*(n-i-1)*(n-i-2)/2;}ll tot=1LL*n*(n-1)*(n-2)/6;printf("%.7f\n",1.0*ans/tot);}return 0;
}