Hide

Problem F
Compass Rose

/problems/mines23.compassrose/file/statement/en/img-0001.png
By Brosen commonswiki - Own work, CC BY 2.5, https://commons.wikimedia.org/w/index.php?curid=667281

Your friend Rose works as an intern at the United States Geologic Survey (USGS) on Mines campus. She has taken you up to a geological site in Boulder and given you some locations at which you are to take geological measurements. Her instructions to get to these locations include headings that you’re having trouble decoding. These headings are strings consisting of between one and ten cardinal directions (N, S, E, and W) and correspond to an angle that you can set your compass to, to travel in the right direction. For example, the heading WSW corresponds to the angle 247.5. Rose’s instructions include a lot of these headings, but you don’t have their corresponding angles memorized, so you decide to write a quick script to do the conversions for you.

Headings are defined as follows.

  • Single character headings (N, S, E, and W) correspond to 0, 180, 90, and 270, respectively.

  • Two character headings (NE, NW, SE, SW) correspond to 45, 315, 135, and 225, respectively.

  • Headings of length n3 are composed of a valid heading of length n1, with one of the characters in that heading prepended to it, to add additional specificity to the heading.

    For example, we take the heading NE (45) but would like to add more specificity. We can prepend either N to form NNE (22.5, halfway between 0 and 45) or E to form ENE (67.5, halfway between 90 and 45).

    Similarly, we can form NNNE (12.25, halfway between 0 and 22.5) and ENNE (33.75, halfway between 22.5 and 45) from NNE by prepending N or E, respectively. However, we cannot prepend S or W (forming SNNE or WNNE) because NNE only contains the cardinal directions N and E, and so we can only prepend those characters to it.

Input

The first line of input contains 1n1000, the number of test cases to follow. Each of the following n lines contains a heading D such that 1|D|10, that is, each heading will be at most 10 characters. You may assume that all headings given follow the definition provided above, and there will not be any invalid headings.

Output

You should output n lines, with the ith line containing a real number, the compass heading (in degrees) corresponding to the given heading Di.

Answers within 108 of the correct answer will be accepted. If a compass heading does not contain a decimal portion, it can be omitted.

Sample Input 1 Sample Output 1
2
W
N
270
0
Sample Input 2 Sample Output 2
6
NW
ESE
ENNE
SESE
WNNNW
WWWSW
315.0
112.5
33.75
123.75
343.125
264.375
Hide

Please log in to submit a solution to this problem

Log in