{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"You are given a rectangular billiard board, **L** and **W** be the length and width of the board respectively. Unlike other billiard boards it doesn\u0027t have any pockets. So, the balls move freely in the board. Assume that initially some balls are in the board and all of them are moving diagonally. Their velocities are same but their direction may be different. When one or more balls bounce off, their position changes but their velocities remains the same.\n\nYou are given the initial positions of the balls and their directions; your task is to find the position of the balls after **K** seconds. The board is placed in the 2D plane such that the boundaries are **(0,0), (L, 0), (L, W)** and **(0, W)**. The positions of the balls are given as 2D coordinates and they all lie inside the board. The directions are given as one of the following {NE, SE, SW, NW}, N, E, S and W denote North, East, South and West respectively. NE means North-East so both **x** and **y** are increasing. The balls are so small that their radii can be thought to be 0. In each second, the balls advance one unit in their direction. Here one unit doesn\u0027t mean Euclidean one unit. For example, if the current position of a ball is **(x,y)** and its direction is NW then in the next second its position will be **(x-1, y+1)**.\n\nWhen two or more balls bounce off, they may change their directions as shown in the pictures below. You can rotate the pictures to get all possible results. Remember that the balls may bounce at non-integer points.\n\n\n\n| ![Bouncing on walls][1] |\n| :-----------------------: |\n| Fig 1: Bouncing on walls |\n\n\n\t\n\n\t\n| ![Bouncing - two balls][2] |\n| :-------------------------------------: |\n| Fig 2: Bounce result between two balls |\n\n\n\n\n\t\n| ![Bounce - three or four balls][3] |\n| :----------------------------------------------: |\n| Fig 3: Bounce result amongst 3 balls and 4 balls |\n\n\n\n[1]: https://static.lightoj.com/images/problem-1324-billiard1-1605601949785.png\n[2]: https://static.lightoj.com/images/problem-1324-billiard2-1605602037839.png\n[3]: https://static.lightoj.com/images/problem-1324-billiard3-1605602103974.png"}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026#8804; 25)**, denoting the number of test cases.\n\t\nEach case starts with a line containing four integers **L W (5 \u0026#8804; W \u0026#8804; L \u0026#8804; 10\u003csup\u003e8\u003c/sup\u003e), n (1 \u0026#8804; n \u0026#8804; 1000)** and **K (1 \u0026#8804; K \u0026#8804; 10\u003csup\u003e8\u003c/sup\u003e)** where **n** denotes the number of balls in the board. Each of the next **n** lines contains two integers **x y** and a string **d**, where **(x, y) (0 \u0026#8804; x \u0026#8804; L, 0 \u0026#8804; y \u0026#8804; W)** denotes the co-ordinate of the ball and **d** can be one of `{NE, SE, SW, NW}` which denotes the direction of the ball respectively. You can safely assume that the balls are placed in different positions initially."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number in a single line. Then print the position of the balls. Sort the positions first by their **x** co-ordinate, and order the ones which have same **x** coordinate by their **y** coordinates all in ascending order."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\n10 5 6 1\n1 4 NW\n1 1 SW\n9 1 SE\n8 3 NE\n9 4 NE\n7 4 NE\n10 5 6 4\n1 4 NW\n1 1 SW\n9 1 SE\n8 3 NE\n9 4 NE\n7 4 NE\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\n0 0\n0 5\n8 5\n9 4\n10 0\n10 5\nCase 2:\n3 2\n3 3\n7 2\n7 3\n8 3\n9 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}