Mr. X stays in a mansion whose door opens in the North. He travels every morning to meet his friend Ms. Y walking a predefined path.
To cut the distance short, one day he decides to construct a skywalk from his place to his friend’s place. Help him to find the shortest distance between the two residences.
-----Input-----
The first line contains a single positive integer T <= 100, the number of test cases. T test cases follow. The only line of each test case contains a string which is the path from X to Y. The integer value represents the distance. The character R or L represents a Right or a Left respectively.
-----Output-----
For each test case, output a single line containing the minimum distance and the direction(N,S,W,E,NE,NW,SE,SW) of Y’s residence with respect to X’s residence. The output distance should have only 1 decimal place with no approximation. Print “0.0” if X’s and Y’s residence coincide.
-----Example-----
Input:
1
2 L 2 R 2 L 1
Output:
5.0NW
Explanation
Mr. X travels 2units and then takes a Left, and then he travels 2units and takes a Right, then after travelling 2units he takes a Left and finally travels 1unit to reach Y’s residence.
(Unlike Input, Output does not have spaces between the distance and direction)
#input must be invalid because no runtime error after handling invalid input

def parse(movestr):
 moves = []
 acc = ""
 for char in movestr:
  char = char.upper()
  if char == "R" or char == "L":
   if acc != "":
    moves.append(int(acc))
   acc = ""
   moves.append(char)
  elif char.isdigit():
   acc += char
  elif len(acc) > 0:
   moves.append(int(acc))
   acc = ""
   
 if len(acc) > 0:
  moves.append(int(acc))
 return moves


def make_move(x,y,direc,dist):
 if direc == 0:
  #north
  y += dist
 elif direc == 1:
  #west
  x -= dist
 elif direc == 2:
  #south
  y -= dist
 elif direc == 3:
  #east
  x += dist
 return x,y


def calc(moves):
 x,y = 0,0
 direc = 0
 for move in moves:
  if move == "L":
   direc = (direc+1)%4
  elif move == "R":
   direc = (direc-1)%4
  else:
   x,y = make_move(x,y,direc,move)
 return x,y


def string(dist):
 d = str(dist)
 k = d.find(".")
 return d[:k+2]

cases = int(input())
for case in range(cases):
 movestr = input().replace(" ","")
 moves = parse(movestr)
 x,y = calc(moves)
 dist = (x**2 + y**2)**0.5
 
 if x == 0:
  if y == 0:
   direc = ""
  elif y < 0:
   direc = "S"
  else:
   direc = "N"
 elif x < 0:
  if y == 0:
   direc = "W"
  elif y < 0:
   direc = "SW"
  else:
   direc = "NW"
 else:
  if y == 0:
   direc = "E"
  elif y < 0:
   direc = "SE"
  else:
   direc = "NE"
 print("%s%s" %(string(dist),direc))
#input must be invalid because no runtime error after handling invalid input

def parse(movestr):
 moves = []
 acc = ""
 for char in movestr:
  char = char.upper()
  if char == "R" or char == "L":
   if acc != "":
    moves.append(int(acc))
   acc = ""
   moves.append(char)
  elif char.isdigit():
   acc += char
  elif len(acc) > 0:
   moves.append(int(acc))
   acc = ""
   
 if len(acc) > 0:
  moves.append(int(acc))
 return moves


def make_move(x,y,direc,dist):
 if direc == 0:
  #north
  y += dist
 elif direc == 1:
  #west
  x -= dist
 elif direc == 2:
  #south
  y -= dist
 elif direc == 3:
  #east
  x += dist
 return x,y


def calc(moves):
 x,y = 0,0
 direc = 0
 for move in moves:
  if move == "L":
   direc = (direc+1)%4
  elif move == "R":
   direc = (direc-1)%4
  else:
   x,y = make_move(x,y,direc,move)
 return x,y


def string(dist):
 d = str(dist)
 k = d.find(".")
 return d[:k+2]

cases = int(input())
for case in range(cases):
 movestr = input().replace(" ","")
 moves = parse(movestr)
 x,y = calc(moves)
 dist = (x**2 + y**2)**0.5
 
 if x == 0:
  if y == 0:
   direc = ""
  elif y < 0:
   direc = "S"
  else:
   direc = "N"
 elif x < 0:
  if y == 0:
   direc = "W"
  elif y < 0:
   direc = "SW"
  else:
   direc = "NW"
 else:
  if y == 0:
   direc = "E"
  elif y < 0:
   direc = "SE"
  else:
   direc = "NE"
 print("%s%s" %(string(dist),direc))