#include #include #include #include #define inf 1e9 #define esp 1e-8 #define NN #define LL long long #define rep(i,s,t) for (int i=s;i<=t;i++) #define red(i,t,s) for (int i=t;i>=s;i--) using namespace std; int n,m; inline int read() { int t=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9')f=(ch=='-')?-1:f,ch=getchar(); while(ch>='0'&&ch<='9')t=t*10+ch-'0',ch=getchar(); return t*f; } int a[1001]; int main() { // freopen("1.in","r",stdin);//freopen("1.out","w",stdout); int T=read(); rep(i,1,T) { int n=read(); int num=0; rep(i,1,n) a[i]=read(); rep(i,1,n) rep(j,1,n) if(i!=j) if(a[i]>a[j])num++; printf("%.6lf\n",(double)num/(double)(n*(n-1))); } return 0; }