Shortest direction
Submissions: 3737   Accuracy:

36.92%

  Difficulty: Basic   Marks: 1

A person wants to go from origin to a particular location, he can move in only 4 directions(i.e East, West, North, South) but his friend gave him a long route, help a person to find minimum Moves so that he can reach to the destination.

Note: You need to print the lexicographically sorted string. Assume the string will have only ‘E’ ‘N’ ‘S’ ‘W’ characters.

Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is S, S is the long route(string).

Output:
Print minimum Moves so that he can reach to the destination.

Constraints:
1 ≤ T ≤ 100
1 ≤  |length of S| ≤ 1000

Example:
Input

2
SSSNEEEW
NESNWES

Output
EESS
E

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.