Kaity is the tournament director for the Berkeley Math Tournament, a tournament so large that Kaity runs it on an infinite 2D plane.
The 2D plane is templatized by an rectangle , the top-left corner being and the bottom-right corner being . Square has an obstacle if and only if square in the template rectangle has an obstacle, where and are respectively remainders when and are divided by and . One can only travel directly between two squares if their Manhattan distance is 1 and both are empty.
Kaity is running the awards ceremony at . She wishes to know for distinct empty points whether someone at can travel to without running into any obstacles.
Constraints
In tests worth 1 mark, .
Input Specification
The first line contains two integers, and .
The next lines contain a string of characters, each character being either .
if it is empty or #
if it contains an obstacle.
The next line contains one integer, .
The next lines contain two integers, and , indicating a query point .
The input is set such that each of these points and will not contain an obstacle.
Output Specification
Output lines. On the th line, output yes
if is reachable. Otherwise, output no
.
Sample Input 1
6 9
..#####..
..#...#..
......#..
..#####..
..#......
..#...#..
5
1 4
5 4
1 -5
5 -5
-1000000000 0
Sample Output 1
yes
no
no
yes
yes
Comments
X Y is misleading, as it connotes an reference to Cartesian Coordinates. X, Y is actually Row, Then Column, which is Y, X in the cartesian system.
If x is negative, then r is negative. Which item in the template grid would a negative r be referring to?
This problem is using the convention that the remainder must be nonnegative and less than the divisor. This is a widely accepted convention which comes into conflict with certain programming language standards - however, contextually it should be clear that this is the definition being used.