#include #include #include #include #include using namespace std; #define maxN 305 #define lson i<<1 #define rson (i<<1)+1 #define piii pair > #define pii pair #define F first #define S second #define mkp(a,b) make_pair(a,b) #define pb(x) push_back(x) typedef long long LL; int a[maxN]; int main() { int T,N; scanf("%d",&T); while(T--) { scanf("%d",&N); for(int i=1;i<=N;i++) scanf("%d",&a[i]); int num = 0; for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) if(a[i]>a[j]) num++; double base = 1.0*N*(N-1); printf("%lf\n",1.0*num/base); } return 0; }