Turning Trominos

시간 제한3초메모리 제한1024 MB

요약
L-트로미노가 첫 사분면을 자기닮음으로 타일링할 때, 주어진 칸을 덮는 트로미노의 방향을 여덟 가지 중에서 판별한다.
난이도

보통10점 중 6점

유형
분할 정복, 재귀, 수학, 구현
정답자
아직 제출이 없습니다

문제

LL trominos,replicated.

The LL-tromino is composed of three unit squares arranged as shown in part A of the illustration to the right. The LL-tromino is also an example of a rep-tile because four LL-trominos can be arranged to make a replica of itself that is twice as tall and twice as wide, as shown in B. Rep-tiles are interesting because, once they can tile themselves, they can recursively tile as much of the plane as we want, as suggested in C and D. Part C is made from four copies of B, and D is made from four copies of C. Figure 1 shows the first quadrant of the plane completely tiled by LL-trominos by repeating the same procedure.

For this problem, you will be given a square in the first quadrant, and your task is to find the orientation of the LL-tromino covering that square. The unit squares of the first quadrant are numbered 0,1,2,…0, 1, 2, \ldots in the xx- and yy-directions, as shown. The dots, in order from left to right, correspond to the first four sample inputs.

Figure 1: LL-trominos tiling the first quadrant.

Figure 2: LL-tromino orientations.

입력

The first line contains an integer nn (1≤n≤10,000)(1 \leq n \leq 10\\, 000), indicating the number of cases that follow. Each case consists of a single line. Each of the next nn lines contains two integers xx and yy, separated by a space, with 0≤x,y≤2600\leq x,y\leq 2^{60}, indicating a particular square in the first quadrant.

출력

For each case, output the orientation of the LL-tromino that covers the given square, one line per case, where the orientations are shown in Figure 2.

예제1

  1. 예제 1

    입력
    5
    0 0
    1 3
    2 7
    7 12
    100 100
    
    예상 출력
    0
    1
    2
    3
    0