#P17099. [ICPC 2017 Qingdao R] Spacecraft

[ICPC 2017 Qingdao R] Spacecraft

Problem Description

The 1010 billion Quapler spacecraft, which launched in October 2016, in Dalian, is staring continuously at a patch of sky containing about 12 rare stars in the WF18 constellation. We are careful to set up the universe as a three dimensional space (x,y,z)(x,y,z). The exact location of our planet is (a,b,c)(a,b,c) and the centre of WF18 constellation is (u,v,w)(u, v, w). The ground detector recorded the initial state of Quapler. It faces the xx direction and the yy direction is on the left side.

The flight recorder captured its all orbit transformations with a total of nn in a timed sequence. Each record as a triple d,s,t\langle d, s, t \rangle describes a rectilinear motion along the current direction of length dd and ending with a directional rotation.

The string ss is one of “R”,“L”,“D”,“U” indicating a rotation with tt radian to the right, the left, the down and the up side respectively. The recorded information is based on relative direction. That is say, the exact meaning of “R”, “L”, “D” and “U” should be discussed in the current direction of Quapler spacecraft itself.

To emphasize the importance of the studying, the scientists need to analyze the shortest distance between Quapler and the target constellation WF18.

Input Format

The first line consisting a number TT (T30000T \le 30000) indicating the number of test cases.

For each test case, the first line contains three float numbers aa, bb and cc where 0a,b,c1000 \le a, b, c \le 100. The second line contains three float numbers u,vu,v and ww where 0u,v,w1000 \le u,v,w \le 100. The third line is the total number of orbit transformation nn (1n301 \le n \le 30). Each of the following nn lines consists a float number dd (0d1000 \le d \le 100), a string ss and a float number tt (0tπ0 \le t \le \pi) described as above.

Output Format

For each test case, the shortest distance as a float number with the precision of 2 digits.

1
0 0 0
1 1 1
7
2 U 1.5708
2 U 1.5708
2 L 1.5708
2 L 1.5708
2 U 1.5708
2 U 1.5708
2 L 1.5708
1.41