#P10944. [2015杭电多校]XYZ and Drops

[2015杭电多校]XYZ and Drops

XYZ and Drops

Problem Description

XYZ is playing an interesting game called "drops". It is played on a rcr * c grid. Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property "size". The waterdrop cracks when its size is larger than 4, and produces 4 small drops moving towards 4 different directions (up, down, left and right). In every second, every small drop moves to the next cell of its direction. It is possible that multiple small drops can be at same cell, and they won't collide. Then for each cell occupied by a waterdrop, the waterdrop's size increases by the number of the small drops in this cell, and these small drops disappears. You are given a game and a position (xx, yy), before the first second there is a waterdrop cracking at position (xx, yy). XYZ wants to know each waterdrop's status after TT seconds, can you help him? 1r1001 \le r \le 100, 1c1001 \le c \le 100, 1n1001 \le n \le 100, 1T100001 \le T \le 10000

Input

The first line contains four integers rr, cc, nn and TT. nn stands for the numbers of waterdrops at the beginning. Each line of the following nn lines contains three integers xix_i, yiy_i, sizeisize_i, meaning that the ii-th waterdrop is at position (xix_i, yiy_i) and its size is sizeisize_i. (1sizei41 \le size_i \le 4) The next line contains two integers xx, yy. It is guaranteed that all the positions in the input are distinct. Multiple test cases (about 100 cases), please read until EOF (End Of File).

Output

nn lines. Each line contains two integers AiA_i, BiB_i: If the ii-th waterdrop cracks in TT seconds, Ai=0A_i = 0, Bi=B_i = the time when it cracked. If the ii-th waterdrop doesn't crack in TT seconds, Ai=1A_i = 1, Bi=B_i = its size after TT seconds.

Sample Input

4 4 5 10
2 1 4
2 3 3
2 4 4
3 1 2
4 3 4
4 4

Sample Output

0 5
0 3
0 2
1 3
0 1

Author

XJZX

Source

2015 Multi-University Training Contest 4