Under construction

Still being built. Things may change

Expogo

Time limit20sMemory limit1024 MB

Summary
Find the shortest string of N, S, E, W jumps of length 1, 2, 4, and so on that lands exactly on (X, Y), or report IMPOSSIBLE.
Level

Medium6 of 10

Topics
Math, Bit manipulation, Implementation
Solved
No attempts yet

Problem

You have just received the best gift ever: an Expogo stick. You can stand on it and use it to make increasingly large jumps.

You are standing at point (0,0)(0, 0) in an infinite two-dimensional backyard. You want to reach a goal point (X,Y)(X, Y), with integer coordinates, in as few jumps as possible. You must land exactly on the goal point. Passing over it during a jump is not enough.

Each jump, you pick a direction: north, south, east, or west. The ii-th jump moves you 2(i−1)2(i-1) units in the chosen direction. The first jump moves 1 unit, the second moves 2 units, the third moves 4 units, and so on.

Determine whether the goal point can be reached. If it can, show how to reach it using as few jumps as possible.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains two integers XX and YY, the coordinates of the goal point.

Output

For each test case, output one line Case #x: y, where xx is the test case number starting from 1. If the goal point cannot be reached, yy is IMPOSSIBLE. Otherwise, yy is a string of one or more characters from N, S, E, and W, giving the directions of the jumps in order. The jumps must land exactly on the goal point after the last jump, and the string must be as short as possible.

Constraints

(X,Y)≠(0,0)(X, Y) \neq (0, 0).

Hint

In Sample 1, you can jump south from (0,0)(0, 0) to (0,−1)(0, -1), then east to (2,−1)(2, -1), then north to (2,3)(2, 3). Two jumps or fewer are not enough. The goal is at least 2+3=52 + 3 = 5 units away, but the first two jumps together cover only 1+2=31 + 2 = 3 units.

Sample 2 is Sample 1 reflected across both axes, so its answer comes from reversing every direction in the answer to Sample 1.

In Sample 3, EWE reaches the target but is not a valid answer, because a shorter route exists.

Figure out why the target in Sample 4 cannot be reached.

Examples1

  1. Example 1

    Input
    4
    2 3
    -2 -3
    3 0
    -1 1
    
    Expected output
    Case #1: SEN
    Case #2: NWS
    Case #3: EE
    Case #4: IMPOSSIBLE