Chef and Yoda

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has arrived in Dagobah to meet with Yoda to study cooking. Yoda is a very busy cook and he doesn't want to spend time with losers. So he challenges the Chef to a series of games, and agrees to teach the Chef if Chef can win at least P of the games. The total number of games is K. The games will be played on a chessboard of size N*M. That is, it has N rows, each of which has M squares. At the beginning of the game, a coin is on square (1, 1), which corresponds to the topleft corner, and every other square is empty. At every step, Yoda and Chef have to move the coin on the chessboard. The player who cannot make a move loses. Chef makes the first move. They can't move the coin to a square where it had been placed sometime before in the game, and they can't move outside chessboard.
In this game, there are two different sets of rules according to which the game can be played:
from (x, y) player can move coin to (x+1, y), (x1, y), (x, y+1), (x, y1) in his turn, if they are valid squares.
from (x, y) player can move coin to (x+1, y+1), (x1, y1), (x1, y+1), (x+1, y1) in his turn, if they are valid squares.
Before every game, the Power of the kitchen chooses one among the two sets of rules with equal probability of 0.5, and the game will be played according to those rules. Chef and Yoda are very wise, therefore they play optimally. You have to calculate the probability that Yoda will teach Chef.
Input
Input begins with an integer T, the number of test cases
Each test case begins with 4 integers N, M, P, K.
Output
For each test case, output a line containing the answer for task. The output must have an absolute error at most 0.000001 (10^{6}).
Constraints and Subtasks
 1 ≤ T ≤ 50
 1 ≤ K
 2 ≤ N, M ≤ 5
 0 ≤ P ≤ K ≤ 5
 2 ≤ N, M ≤ 10
 0 ≤ P ≤ K ≤ 10^3
 2 ≤ N, M ≤ 100
 0 ≤ P ≤ K ≤ 10^3
 2 ≤ N, M ≤ 100
 0 ≤ P ≤ K ≤ 10^6
Subtask 1 : 10 points
Subtusk 2 : 10 points
Subtusk 3 : 20 points
Subtusk 4 : 60 points
Example
Input: 2 2 3 2 3 2 2 5 5 Output: 0.500000 1.000000
Author:  omelyanenko 
Tester:  mgch 
Tags  omelyanenko 
Date Added:  26042015 
Time Limit:  1.5 sec 
Source Limit:  50000 Bytes 
Languages:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.4, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions