For each query number pair, find the points on a clockwise square spiral, then check whether they lie on the same side of a given line.
Medium6GeometryMathSimulationNo attempts yetTime limit2sMemory limit512 MBAn army stationed at a border decided to number the coordinates around it so that the enemy would have a hard time telling which positions it refers to if the radio signal used for communication were intercepted. The numbering works as follows. First, the army decides where the x and y axes lie. Next, it fixes a linear equation that describes the position of the border relative to the axes (the border is a straight line). Finally, it numbers every integer point of the Cartesian plane that is not on the border. The point (0,0) gets the number 0, and from there the integer points are numbered along a clockwise spiral, always skipping the points that lie on the border (see Figure 1). If the point (0,0) lies on the border, the number 0 goes to the first point in the given order that is not on the border.

Figure 1: Numbering of the integer points
As the figure shows, the spiral moves from (0,0) to (−1,0). For each integer k≥1, the points with max(∣x∣,∣y∣)=k are visited starting at (−k,−k+1), going up to (−k,k), then right to (k,k), then down to (k,−k), then left to (−k,−k). The spiral then repeats the same pattern for k+1.
The enemy cannot tell which position the army refers to unless it knows the numbering system. The scheme also made life hard for the army, because it is now difficult to decide whether two given points are on the same side of the border or on opposite sides. That is where they need your help.
The input contains several test cases. The first line holds an integer T (1≤T≤100), the number of test cases. The T test cases follow.
The first line of each test case holds two integers a and b (−5≤a≤5, −10≤b≤10) that describe the border equation y=ax+b. The second line holds an integer K (1≤K≤1000), the number of queries that follow. Each of the next K lines describes one query with two integers M and N (0≤M,N≤65535), the numbers assigned to two points.
For each test case, print K+1 lines. The first line identifies the test case in the form Caso X, where X is the test case number starting from 1. The next K lines hold the answers to the K queries in input order. If the points numbered M and N are on the same side of the border, print
Mesmo lado da fronteira
and otherwise print
Lados opostos da fronteira