**Chess Rush SOLUTION Codeforces**

**Chess Rush SOLUTION Codeforces**

The mythic universe of Chess Land is a rectangular framework of squares with R lines and C segments, R being more prominent than or equivalent to C. Its lines and segments are numbered from 1 to R and 1 to C, individually.

The occupants of Chess Land are typically referenced as pieces in ordinary language, and there are 5 explicit sorts of them wandering the land: pawns, rooks, clerics, sovereigns and rulers. In opposition to mainstream thinking, valor is long dead in Chess Land, so there are not a single knights in sight.

Each piece is interesting in the manner it moves around from square to square: in one stage,

a pawn can push one line ahead (for example from line r to r+1), without evolving sections;

a rook can move quite a few sections left/directly without changing lines OR push quite a few lines ahead/in reverse without evolving segments;

a priest can move to any square of the two diagonals crossing at its presently involved square;

a sovereign can move to any square where a rook or a cleric could move to from her position;

also, a ruler can move to any of the 8 contiguous squares.

In the accompanying figure, we set apart by X the squares each piece can move to in a solitary advance (here, the lines are numbered from base to top, and the segments from left to right).

As of late, Chess Land has become a hazardous spot: pieces that are going through the land can get caught surprisingly by obscure powers and essentially vanish. As an outcome, they might want to arrive at their objections as quick (for example in as hardly any moves) as could reasonably be expected, and they are likewise keen on the quantity of various ways it is feasible for them to arrive at it, utilizing the insignificant number of steps – on the grounds that more ways being accessible could mean lower odds of getting caught. Two ways are viewed as various on the off chance that they vary in at any rate one visited square.

For this issue, let us expect that pieces are entering Chess Land in a given section of line 1, and leave the land in a given segment of column R. Your assignment is to address Q questions: given the sort of a piece, the section it enters line 1 and the segment it must reach in column R so as to exit, process the negligible number of moves it needs to make in Chess Land, and the quantity of various ways it can do as such.

Info

The main line contains three space-isolated numbers R, C, and Q (1≤Q≤1000, 2≤C≤1000 and C≤R≤109) – the quantity of lines and sections of Chess Land, and the quantity of inquiries, individually. At that point Q lines follow.

Each line comprises of

a character T, relating to the sort of the piece being referred to (‘P’ for pawn, ‘R’ for rook, ‘B’ for priest, ‘Q’ for sovereign and ‘K’ for lord);

two numbers c1 and cR, 1≤c1,cR≤C, indicating that the piece begins from the c1-th segment of line 1, and needs to arrive at the cR-th section of column R.

Yield

You need to print Q lines, the I-th one containing two space isolated numbers, the response to the I-th question: the first is the insignificant number of steps required, the second is the quantity of various ways accessible utilizing this number of steps. Since the appropriate response can be very enormous, you need to figure it modulo 109+7.

On the off chance that it is difficult to arrive at the objective square, yield the line “0”.