Associated Course(s):
Geeks Classes in Noida

Given an NxN chessboard and a Knight at position (x,y). The Knight has to take exactly K steps, where at each step it chooses any of the 8 directions uniformly at random. What is the probability that the Knight remains in the chessboard after taking K steps, with the condition that it can’t enter the board again once it leaves it.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains four integers N, X, Y and K. Where N * N is the size of the board and (X, Y) denotes the starting position of the chess piece.

**Output:**

Output the probability that the knight remains on the board. Print the answer exactly upto 6 decimal places for each testcase in a new line.

**Constraints:**

1<= T <=100

0<= N, K, X, Y <=100

**Example:**

Input:

1

8 0 0 3

Output:

0.125000

Author: sujnesh

BadiMehnatLagtiHaiEasySawalMe | 480 |

Jihye Sofia Seo | 187 |

RohitBattu | 176 |

MaaChudaApniBadiMehnatLagtiHaiEasySawal | 173 |

piyushmittal25 | 172 |

AdityaSharma16 | 490 |

BadiMehnatLagtiHaiEasySawalMe | 480 |

saumitra13325 | 452 |

blackshadows | 430 |

ashujack | 401 |

blackshadows | 5188 |

akhayrutdinov | 5099 |

Ibrahim Nash | 5071 |

Quandray | 4354 |

sanjay05 | 3668 |

Login to report an issue on this page.