Sheepwalking

Two sheepdogs block two neighboring cells each turn to steer a randomly moving sheep home and minimize its expected number of moves there.

Hard9ProbabilityGame theoryMathNo attempts yetTime limit20sMemory limit1024 MB

Problem

Bleatrix the sheep lives on an infinite grid of unit cells. Her home is the cell (0,0)(0, 0), and every coordinate is given relative to that cell. Bleatrix sleepwalks, so right now she is in the cell (X,Y)(X, Y), which is XX columns east of and YY rows north of her home. The two sheepdogs assigned to protect her have just noticed that she is missing, and they want to herd her back home.

Before each of Bleatrix's moves, the two sheepdogs move to any cells they want. They may not both move to the same cell, and neither may move to the cell Bleatrix is standing on. Once the sheepdogs are in place, Bleatrix takes the four unit moves (north, south, west, east), discards the ones that would take her into a cell with a sheepdog, and chooses uniformly at random among the moves that remain. Then the sheepdogs position themselves again, and so on. Unlike Bleatrix, the sheepdogs do not have to make unit moves.

Once Bleatrix reaches her home at (0,0)(0, 0) she wakes up and grazes, and she makes no further moves.

The sheepdogs coordinate to minimize the expected number of moves Bleatrix makes before she reaches home. Compute that expected number.

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 cell Bleatrix is sleepwalking in.

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 11, and yy is the expected number of Bleatrix's moves written with exactly six digits after the decimal point. The exact answer never falls on a rounding boundary at the sixth decimal digit, so the value you print is uniquely determined.

Constraints

  • 1T1001 \le T \le 100
  • 1000X1000-1000 \le X \le 1000
  • 1000Y1000-1000 \le Y \le 1000
  • (X,Y)(0,0)(X, Y) \ne (0, 0)

Hint

XX and YY may be negative. An XX of 1-1 means the cell is one unit west of Bleatrix's home cell, and a negative YY means the cell is south of her home cell.

Consider X=1X = -1 and Y=1Y = 1, so Bleatrix starts one cell west of and one cell north of her home. Before her first move, the two sheepdogs can position themselves in the cells (2,1)(-2, 1) and (1,2)(-1, 2). Whichever direction she then chooses, she ends up one step away from home. That still does not guarantee that she goes home on her next move, because the sheepdogs can block only two cells and Bleatrix picks at random between the two that are left. The remaining details are left for you to discover.