Under construction

Still being built. Things may change

Legacy Screensaver

Time limit3sMemory limit2048 MB

Summary
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 WW pixels wide and HH pixels high. The origin is the top-left corner of the screen, the xx-axis points right from the origin, and the yy-axis points down.

Rectangle ii (i=1,2i = 1, 2) is wiw_i pixels wide and hih_i pixels high. Its top-left corner starts at (xi,yi)(x_i, y_i), and its initial direction of movement is (δxi,δyi)(\delta x_i, \delta y_i), where each of δxi\delta x_i and δyi\delta y_i is −1-1 or 11. At the end of each second, the top-left corner of rectangle ii instantly changes by (δxi,δyi)(\delta x_i, \delta y_i).

When rectangle ii touches the left or right border of the screen, δxi\delta x_i changes sign before the next second. Likewise, when it touches the top or bottom border, δyi\delta y_i changes sign before the next second. If rectangle ii touches two borders at the same time, which can only happen at a corner of the screen, both δxi\delta x_i and δyi\delta y_i 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 f(t)f(t) be the number of integers τ=0,1,…,t−1\tau = 0, 1, \ldots, t - 1 such that the rectangles overlap during second τ\tau (second 00 is the time before the rectangles start moving).

Find the limit of f(t)t\frac{f(t)}{t} as t→∞t \rightarrow \infty, as an irreducible fraction. It can be shown that this limit is rational.

Input

The first line contains the number of test cases TT (1≤T≤10001 \le T \le 1000). Each test case follows.

The first line of each test case contains two integers WW and HH, the width and height of the screen (3≤W,H≤40003 \le W, H \le 4000).

The next two lines describe the two rectangles. Each rectangle is given by six integers wiw_i, hih_i, xix_i, yiy_i, δxi\delta x_i, δyi\delta y_i, which are its width, height, top-left corner coordinates, and initial direction. The constraints are 1≤wi≤W−21 \le w_i \le W - 2, 1≤hi≤H−21 \le h_i \le H - 2, 0<xi<W−wi0 < x_i < W - w_i, 0<yi<H−hi0 < y_i < H - h_i, and δxi,δyi∈\delta x_i, \delta y_i \in −1-1 or 11.

The sum of W+HW + H over all test cases does not exceed 8000.

Output

For each test case, print a non-negative integer pp and a positive integer qq separated by a slash (/) with no spaces, so that the limit of f(t)t\frac{f(t)}{t} as t→∞t \rightarrow \infty equals pq\frac{p}{q}. The fraction must be irreducible, so the greatest common divisor of pp and qq 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 τ=0\tau = 0 and τ=6\tau = 6. So, for example, f(8)=2f(8) = 2.

Examples1

  1. Example 1

    Input
    2
    3 3
    1 1 1 1 1 1
    1 1 1 1 1 -1
    5 4
    2 2 1 1 -1 -1
    2 1 2 2 1 -1
    
    Expected output
    1/2
    1/3