Avast, ye scallywags! Blackbeard was an English pirate of the early 18th century. Although he was known for looting and taking ships, he commanded his vessels with the permission of their crews. There are no accounts of him ever harming or murdering his captives.

This challenge is in honor of the infamous Blackbeard and inspired by International Talk Like a Pirate Day (September 19). It is also the inverse of this challenge by Pyrrha.



The Challenge

Create a program that takes a treasure map as an input (composed of the characters listed below), and outputs it's directions.



Input

All inputs will consist of v, &gt;, &lt;, ^, whitespace, and a single X.

You can assume the following:


the map will never loop or cross itself
the starting arrow will always be the bottommost character in the leftmost column
there will always be a treasure (X)


A sample input is shown below.

  &gt;&gt;v   &gt;&gt;&gt;&gt;&gt;&gt;v
  ^ v   ^     v
  ^ v   ^   v&lt;&lt;
  ^ v   ^   v
  ^ &gt;&gt;&gt;&gt;^   &gt;&gt;X
  ^
&gt;&gt;^




Output

The output should be a ", "-delimited string of directions. Below is the correct output from the above map.

E2, N6, E2, S4, E4, N4, E6, S2, W2, S2, E2


A single trailing newline or space is permitted.



Examples

In:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;v
               v
               v
               &gt;&gt;&gt;&gt;X

Out:
E15, S3, E4

In:
&gt;&gt;&gt;&gt;&gt;&gt;v
^     v
^     &gt;&gt;&gt;&gt;X

Out:
N2, E6, S2, E4

In:
X
^
^
^

Out:
N3

In:
&gt;&gt;&gt;&gt;&gt;&gt;v
^     v
^     v
      v
      &gt;&gt;&gt;&gt;&gt;&gt;X

Out:
N2, E6, S4, E6

In:
 X
 ^
 ^
&gt;^

Out:
E1, N3

In:
&gt;X

Out:
E1

In:
v&lt;&lt;&lt;&lt;&lt;
vX&lt;&lt;&lt;^
&gt;&gt;&gt;&gt;^^
&gt;&gt;&gt;&gt;&gt;^

Out:
E5, N3, W5, S2, E4, N1, W3




Happy International Talk Like a Pirate Day!
CJam, 86 bytes

qN/_,{1$=cS-},W=0{_3$3$==_'X-}{"^v&lt;&gt;"#_"NSWE"=L\+:L;"\(\ \)\ ( )"S/=~}w];Le`{(+}%", "*


Try it online

Explanation:

qN/     Get input and split into rows.
_,      Calculate number of rows.
{       Loop over row indices.
  1$=     Get row at the index.
  c       Get first character.
  S-      Compare with space.
},      End of filter. The result is a list of row indices that do not start with space.
W=      Get last one. This is the row index of the start character.
0       Column number of start position. Ready to start tracing now.
{       Start of condition in main tracing loop.
  _3$3$   Copy map and current position.
  ==      Extract character at current position.
  _'X-    Check if it's the end character `X.
}       End of loop condition.
{       Start of loop body. Move to next character.
  "^v&lt;&gt;"  List of directions.
  #       Find character at current position in list of directions.
  _       Copy direction index.
  "NSWE"  Matching direction letters.
  =       Look up direction letter.
  L\+:L;  Append it to directions stored in variable L.
  "\(\ \)\ ( )"
          Space separated list of commands needed to move to next position for each of
          the 4 possible directions.
  S/      Split it at spaces.
  =       Extract the commands for the current direction.
  ~       Evaluate it.
}w      End of while loop for tracking.
];      Discard stack content. The path was stored in variable L.
Le`     Get list of directions in variable L, and RLE it.
{       Loop over the RLE entries.
  (+      Swap from [length character] to [character length].
}%      End of loop over RLE entries.
", "*   Join them with commas.