#include #include #include #include using namespace std; #define N 305 int arr[N]; int main() { int test, n; scanf("%d", &test); for (int cas = 1; cas <= test; cas++) { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", arr + i); int cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (j == i) continue; if (arr[i] < arr[j]) { cnt++; } } } double res = (double)cnt / (n * (n - 1)); printf("%.6f\n", res); } return 0; }