God! Save me

Let there be n doors in a mine contained room. If you choose i-th door, it either takes you to a safe place after xi hours or it returns you to the same room after xi hours traveling. What is the expected length of time (in hours, let P ) until you can move to the safe place? Input The first line in the input file is an integer representing the number of test cases. Each of the test cases follows below. The first line of each case consists an integer denoting the value of n (0 < n < 100). Each of the next n lines contains the value of xi, 0 < |xi| < 25 (if positive it takes you out, if negative it returns you) and pi denoting the probability to choose the i-th door. You can assume that the sum of all pi equals 1. There may be arbitrary number of spaces between the values. Output Foreachtestcase,firstprinttheserialnumberofthecase,acolon,anspaceandthenprint‘God! Save me’ (without the quotes) if you can’t expect to be in the safe place, else print the value of P corrected to two digits after decimal point. Check the sample input & output. Sample Input 2 3 2 0.33 -3 0.33 -5 0.34 3 2 0.34 -3 0.33 -5 0.33 Sample Output Case 1: 10.15 Case 2: 9.76