Alice is feeling bored while sitting on the riverbank with her sister, when she notices a 2D White Rabbit with a 2D pocket watch run past. She follows it down a rabbit hole when suddenly she falls a long way to a curious 2D plane.
In this 2D plane she discovered she can only move using a sequence of movements. Those movements are limited to:
- Scaling, denoted as (where is a nonzero rational number). If Alice is currently at , then takes her to .
- Translation, denoted as (where and are rational numbers). If Alice is currently at , then takes her to .
- Rotation, denoted as (where and are rational numbers and ). If Alice is currently at , then takes her to . In other words, is a clockwise rotation about the origin, at an angle where and .
- Flip X-axis, denoted as . If Alice is currently at , then takes her to .
- Flip Y-axis, denoted as . If Alice is currently at , then takes her to .
- Inversion, denoted as (more precisely, inversion in the unit circle). If Alice is currently at , then takes her to .
Also, Alice discovered that when she is at before she performs an inversion, she is taken to a special place called Wonderland. In Wonderland, performing any of the other movements (scaling, translation, rotation or flip) will return her to Wonderland, and performing an inversion moves her back to .
Now, Alice has a sequence of such movements to make. Moreover, she performs this sequence of movements a total of times. Your task is to determine her final location after her adventure.
If Alice's final location is , it's easy to see that and are rational. Let and (both in lowest terms). Understandably, , , and can be really large integers, so instead of asking for and we will only ask for the values and .
Input Format
The first input contains a single integer, , which is the number of test cases. The next lines contain the descriptions of the test cases.
The first line of each test case contains four values , , and . and are integers (described above), and is the initial location of Alice ( and are rational numbers).
The next lines each contains the description of a movement in the sequence, which is one of the following:
S c
, which denotes scaling ( is a nonzero rational number),T a b
, which denotes translation ( and are rational numbers),R a b
, which denotes rotation ( and are rational numbers and ),F X
, which denotes flip X-axis,F Y
, which denotes flip Y-axis, andI
, which denotes inversion.
Output Format
If Alice's final location is Wonderland, output WONDERLAND
.
If Alice's final location is , and and in irreducible form, then output the two integers and in a line separated by a single space. However, if either or is not invertible, also output WONDERLAND
.
Constraints
The sum of the 's in a single test file is
Each rational number is expressed in irreducible form with the following constraints:
Sample Input
2
3 2 0/1 0/1
T -2/1 3/1
R 3/5 4/5
I
5 1 2/1 -2/1
F X
S 3/2
T -3/1 -3/1
I
F Y
Sample Output
881896558 492241383
WONDERLAND
Explanation
In the first test case, , and the sequence of operations is .
Therefore, the final location is . So we print:
and:
.
In the second test case, , and the sequence of operations is .
Therefore, the final location is Wonderland.