This page is still under construction.

Parts of this page are still being built. What you see may change.

Particle

Time limit1sMemory limit256 MB

Summary
Decide whether a point bouncing off rectangle walls with fixed velocity reaches target A before target B or neither.
Level

Medium7 of 10

Topics
Number theory, Geometry
Solved
No attempts yet

Problem

A particle moves inside a W by H rectangle with constant velocity (a,b). It reflects off walls like light on a mirror, and at a corner it reverses direction. Starting from (x0,y0), decide whether it reaches A=(x1,y1) before B=(x2,y2), the opposite order, or neither ever.

Input

The first line has T test cases. Each test case is one line with W, H, x0, y0, x1, y1, x2, y2, a, b.

Output

Print A if A is reached first, B if B is reached first, or O if neither is reached.

Examples4

  1. Example 1

    Input
    3
    5 5 1 3 4 2 2 1 1 1
    5 3 1 2 0 2 3 0 3 2
    5 3 2 2 2 1 3 2 1 3
    
    Expected output
    A
    B
    O
    
  2. Example 2

    Input
    1
    6 6 1 1 5 5 3 3 1 1
    
    Expected output
    B
    
  3. Example 3

    Input
    1
    4 4 2 2 3 3 1 1 1 1
    
    Expected output
    A
    
  4. Example 4

    Input
    1
    7 5 3 2 6 4 1 1 2 3
    
    Expected output
    B