Ants
There are K ants running along coordinate grid lines inside the field. A field of size w × h centimeters has one corner at (0, 0) and another one at (w, h). Each ant can run in one of 4 directions with speed 1 centimeter per second.
Since ants are very proud creatures, they never give way. Thus, if several ants face head-on, they immediately turn around and run in the opposite direction. When two ants run perpendicular they will not payattention to each other. If an ant reaches the boundary of the field it also turns around and runs back.You are given positions and directions of movement of all the ants in initial moment of time. Find theirpositions and directions of movement after t seconds.
Input
The first line contains 4 integers: w, h, k, t (1 ≤ w, h, k ≤ 100, 1 ≤ t ≤ 10^9
).
Each of the following k lines contains 3 integers: x[i]
, y[i]
, d[i]
, where (x[i]
, y[i]
) - coordinates the ith ant, d[i]
- direction of his movement (0 < x[i]
< w, 0 < y[i]
< h, 1 ≤ d[i]
≤ 4). d[i]
= 1 if ant moves in direction of increasing x, d[i]
= 2 - in direction of increasing y, d[i]
= 3 - in direction of decreasing x, d[i]
= 4 - in direction of decreasing y.
All of the numbers in lines are separated by single spaces. All ants are located in different points.
Output
Output consists of exactly k lines - one line for each ant in the same order as they are given in the input. Each line contains 3 integers separated by single spaces - coordinates of the ant and direction of his movement.