406357: GYM102388 C Snooker

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Snookertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

On Planet E, people enjoy playing snooker!

Unlike snooker on Earth, there is only one ball on Planet E, and no pockets on the table. Let the length of the table be $$$m$$$ and the width of the table be $$$n$$$. Then the positions on the table can be represented by $$$(x, y)$$$ where $$$0 \le x \le m$$$ and $$$0 \le y \le n$$$. We view the ball as a point without radius.

The goal is to move the ball from $$$(x_0, y_0)$$$ to $$$(x_1, y_1)$$$, with exactly $$$k$$$ bounces from the table walls.

This figure demonstrates 2 bounces. The ball moves in straight line and the reflection angle must be the same. Note that if the ball moves to a corner, it will move back in the exactly opposite direction with 2 bounces. See testcase 2 in the sample.

Can you help the people on Planet E to find the shortest distance the ball has to travel to achieve the goal?

Input

The first line contains a positive integer $$$T$$$ ($$$T \le 100$$$), the number of testcases.

Each testcase contains 7 integers $$$m, n, x_0, y_0, x_1, y_1, k$$$ ($$$2 \le m \le 100$$$, $$$2 \le n \le 100$$$, $$$0 < x_i < m$$$ and $$$0 < y_i < n$$$ for $$$i = 0, 1$$$, and $$$0 \le k \le 100$$$), representing the table size (length $$$m$$$, width $$$n$$$) and the goal $$$(x_0, y_0)$$$ to $$$(x_1, y_1)$$$ with exactly $$$k$$$ bounces.

Output

For each testcase, output a single line consisting of the shortest distance the ball has to travel, corrected to $$$2$$$ decimal places.

ExampleInput
4
100 100 1 1 1 1 0
100 100 1 2 1 2 2
100 100 1 1 1 1 3
100 50 1 2 3 4 5
Output
0.00
4.47
200.01
198.04

加入题单

算法标签: