Stretching Geometry

A square shaped garden is marked with integer coordinates. The area of the garden is infinite. The lower left corner of the garden is O (0,0) and the coordinate system is like normal Cartesian coordinate system. A mad problem setter has planted (15001*15001) trees in 15001 rows and 15001 columns. So the area where trees are planted is also a square. Trees are planted in a coordinate (p,q) iff the following two conditions are true: a) d|p and d|q b) p ≤ 15000d and q ≤ 15000d. Here d is an arbitrary integer (0 < d < 11). In figure 1 below the value of d is 4.

2/2 The mad problem setter has drawn a 2D image of this garden, which looks somewhat like Figure 1 but a lot larger. But the problem is that while manipulating the image with a high precision imaging software he has stretched the image b (b > 0) times along x-axis and a (a > 0) times along y-axis. For example Figure 2 is found by stretching Figure-1, 3 times along x-axis and 2 times along y-axis. The trees in the pictures can be considered point objects. So they remain point objects after any sort of stretching. Before or after this stretching not all trees are visible from the origin O (0, 0) due to some other trees, which are on the same line with respect to O. In the above pictures the visible trees are shown with red. You will be given the coordinate of one of the visible trees in this stretched figure A (x1, y1). There will always be a tree at position B (x2, y2) in this stretched figure that is visible from O and whose angular distance φ from A with respect to O is minimum (I mean angle AOB is minimum) and in the positive direction (Counter clockwise). Your job is to determine the coordinate of B (x2, y2). Of course, the mad problemsetter is looking for a very efficient solution. Input The input file contains less than 10001 lines of input. Each line contains four integers x1 (0 ≤ x1 ≤ 15000∗d∗b), y1 (0 ≤ y1 ≤ 15000∗d∗a), d (0 < d < 11), ab (0 < ab ≤ 100000000, ab means a∗b) and φ (expressed in degree). The meanings of these symbols are described in the problem statement. Input is terminated by a line where the value of x1 is ‘-1’. This line should not be processed. φ will always be in the format D.DDDDDDDDDDDDDDDeN, here D denotes any decimal digit and N is an integer (−4 > N > −16). (If you are intelligent and use floating-point number with reasonable precision (such as double in C/C++) then you should not have any trouble.) Output For each line of input except the last one produce one line of output which contains two integers which are the values of x2 and y2. Sample Input 152896 108 4 36 1.058827657765851e-6 43492 24 2 6 5.815846810938229e-7 -1 -1 -1 -1 1.000000000000000e-8 Sample Output 203856 144 54364 30