Calgary Collegiate Programming Competition 2019

Start

2019-03-09 20:00 UTC

Calgary Collegiate Programming Competition 2019

End

2019-03-10 00:00 UTC
The end is near!
Contest is over.
Not yet started.
Contest is starting in -249 days 23:52:22

Time elapsed

4:00:00

Time remaining

0:00:00

Problem E
DVD Screensaver

You may remember old DVD screensavers where the logo bounces around the edges of the screen. Of course, the most satisfying moment is when the logo bounces off one of the corners of the screen.

Johnny would like to know when the logo will collide with a corner of the screen. Using an Euclidean coordinate system centered at the bottom-left corner of the screen with the y-axis pointing up (such that a coordinate of $(x, y)$ corresponds to a point $x$ cm to the right and $y$ cm above the bottom-left corner), he models the problem as follows. The TV screen is an axis-aligned rectangle $w_ s$ cm wide and $h_ s$ cm high. The logo is an axis-aligned rectangle $w_ l$ cm wide and $h_ l$ cm high. Initially, the bottom-left corner of the logo is at coordinates $(x_ l, y_ l)$, and the logo moves one cm right and one cm up per second. When the logo collides with the edge of the screen, it is reflected such that the angle of reflection is equal to the angle of incidence.

Input

The first line contains a single integer $T$, denoting the number of test cases. It is guaranteed that $1\leq T\leq 1\, 000$.

Each of the next $T$ lines of input contains six integers: $w_ s, h_ s, w_ l, h_ l, x_ l, y_ l$, corresponding to single test case. It is guaranteed that $2\leq w_ s, h_ s\leq 10^9$, $1\leq w_ l<w_ s$, $1\leq h_ l<h_ s$, $0\leq x_ l\leq w_ s-w_ l$, and $0\leq y_ l\leq h_ s-h_ l$.

Output

If the logo will collide with one of the corners of the screen after a finite time span, print a single non-negative integer $T$ denoting the number of seconds that passes before the logo collided with any corner of the screen. Otherwise, print “Johnny will die waiting” (without quotes).

Sample Input 1 Sample Output 1
3
9 6 3 3 1 1
3 3 1 1 1 0
10 10 1 1 2 2
5
Johnny will die waiting
7