Screensaver

No attempts yetTime limit1sMemory limit128 MB

Problem

Bajtazar just started a new job at a 3D-graphics company and received a new computer with an enormous-resolution monitor. To test the hardware, he decided to write a screensaver based on the classic idea of a ball bouncing around the screen.

Every wall is a horizontal or vertical segment, and no two walls share any common point. The ball always travels at a 45-degree angle to the walls and bounces according to the law of reflection: it always reflects at 45 degrees to the surface it hits, whether it strikes the middle of a wall or one of its endpoints.

Given the arrangement of the walls and a time tt, determine the position of the ball after the screensaver has been running for tt byte-seconds.

Input

The first line contains three integers ss (1s500001 \le s \le 50000), kk (0k30 \le k \le 3) and tt (0t10180 \le t \le 10^{18}): the number of walls, the ball's initial direction of movement, and the time (in byte-seconds) at which its position is requested. The directions kk mean:

  • 00: north-east (xx and yy both increase)
  • 11: south-east (xx increases, yy decreases)
  • 22: south-west (xx and yy both decrease)
  • 33: north-west (xx decreases, yy increases)

Each of the next ss lines contains four integers pxp_x, pyp_y, kxk_x, kyk_y (0px,py,kx,ky1090 \le p_x, p_y, k_x, k_y \le 10^9): the coordinates of the two endpoints of one wall. The total length of the walls ll and the number of walls ss satisfy l+s100000l + s \le 100000. The ball starts from the midpoint of the first wall, moving in direction kk, and in each byte-second it moves one unit along both the xx and yy axes. The length of the first wall (the one the ball starts from) is always even.

Output

Print, on a single line, the position of the ball at time tt: two integers, the xx and yy coordinates, separated by a single space.