Legacy Screensaver
Time limit3sMemory limit2048 MB
Two bouncing rectangles move around a W by H screen; find the long-run fraction of seconds in which their interiors overlap.
- Level
Hard8 of 10
- Topics
- Math, Number theory, Simulation
- Solved
- No attempts yet
Problem
On a very old operating system, a screensaver consists of two rectangles flying around the screen. The screen is pixels wide and pixels high. The origin is the top-left corner of the screen, the -axis points right from the origin, and the -axis points down.
Rectangle () is pixels wide and pixels high. Its top-left corner starts at , and its initial direction of movement is , where each of and is or . At the end of each second, the top-left corner of rectangle instantly changes by .
When rectangle touches the left or right border of the screen, changes sign before the next second. Likewise, when it touches the top or bottom border, changes sign before the next second. If rectangle touches two borders at the same time, which can only happen at a corner of the screen, both and change sign.
The rectangles always stay fully within the screen. In short, collisions with the screen borders are perfectly elastic. Movement is still discrete, though: at the end of each second, each rectangle moves 1 pixel in both directions at once.
The two rectangles overlap when their intersection has positive area. Let be the number of integers such that the rectangles overlap during second (second is the time before the rectangles start moving).
Find the limit of as , as an irreducible fraction. It can be shown that this limit is rational.
Input
The first line contains the number of test cases (). Each test case follows.
The first line of each test case contains two integers and , the width and height of the screen ().
The next two lines describe the two rectangles. Each rectangle is given by six integers , , , , , , which are its width, height, top-left corner coordinates, and initial direction. The constraints are , , , , and or .
The sum of over all test cases does not exceed 8000.
Output
For each test case, print a non-negative integer and a positive integer separated by a slash (/) with no spaces, so that the limit of as equals . The fraction must be irreducible, so the greatest common divisor of and is 1.
Hint
In the second test case, the state of the rectangles during the first few seconds is shown in the pictures below. The rectangles overlap during seconds and . So, for example, .



