Xeno-archaeology (Small)

Given colored tiles from an infinite square ring pattern, find the pattern center that fits all tiles with the stated tie breaks.

Medium6Brute forceMathGeometryNo attempts yetTime limit5sMemory limit512 MB

Problem

An alien civilization built a giant monument long ago. Its floor looked like this:

###############
#.............#
#.###########.#
#.#.........#.#
#.#.#######.#.#
#.#.#.....#.#.#
#.#.#.###.#.#.#
#.#.#.#.#.#.#.#
#.#.#.###.#.#.#
#.#.#.....#.#.#
#.#.#######.#.#
#.#.........#.#
#.###########.#
#.............#
###############

A # is a red tile and a . is a blue tile. The pattern went on for miles in every direction, so treat it as infinite. Methane rain and dust storms have destroyed almost all of it, and only a few tiles are left.

The pattern has one center (X,Y)(X, Y). The tile at (x,y)(x, y) is red when max(xX,yY)\max(|x - X|, |y - Y|) is odd, and blue when that value is even. In the picture above the center is the single blue tile in the middle.

Given the position and the color of every remaining tile, find the center of the pattern.

Input

The first line contains the number of test cases TT. Each test case starts with a line containing NN, the number of remaining tiles. Each of the next NN lines contains XiX_i, YiY_i, and the color of that tile, which is either # or ..

Limits

  • 1T501 \le T \le 50
  • 1N1001 \le N \le 100
  • 100Xi100-100 \le X_i \le 100
  • 100Yi100-100 \le Y_i \le 100
  • No two tiles in the same test case share a position.

Output

For each test case, print one line of the form Case #c: X Y, where cc is the test case number starting from 1 and (X,Y)(X, Y) is the center of the pattern. If more than one center is possible, print the one closest to (0,0)(0, 0) in Manhattan distance, that is, the distance in xx plus the distance in yy. If several centers are still tied, print the one with the largest XX. If there is still a tie, print the one with the largest YY. If no center is possible, print Case #c: Too damaged instead.