Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to 1 meter movement in the south, north, west or east direction respectively).

It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second.

Find the skier's time to roll all the path.

Input

The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.

Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed 10^5 characters.

The sum of the lengths of t given lines over all test cases in the input does not exceed 10^5.

Output

For each test case, print the desired path time in seconds.

Example

Input


5
NNN
NS
WWEN
WWEE
NWNWS


Output


15
6
16
12
25
import java.lang.String;
import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
//class Main    //AtCoder
//class Solution // Codechef
public class Solution2 //Codeforces
{
    public static void main(String args[])
    {
        try {
            FastReader sc = new FastReader();
            int TT = sc.nextInt();
            for(int hehe=1 ; hehe  <= TT ; hehe++){
                String str=sc.nextLine();
                int x=0,y=0;
                long ans=0;
                HashSet<String> hs=new HashSet<>();
                for(int i=0;i<str.length();i++)
                {
                    char ch=str.charAt(i);
                    String prev=x+","+y;
                    if(ch=='N')
                    {
                        y+=1;
                    }
                    if(ch=='E')
                    {
                        x+=1;
                    }
                    if(ch=='W')
                    {
                        x-=1;
                    }
                    if(ch=='S')
                    {
                        y-=1;
                    }
                    String path=prev+"-"+x+","+y;
                    String ultaPath=x+","+y+"-"+prev;
                    if(hs.contains(path) || hs.contains(ultaPath)) {
                        ans += 1;
                        //hs.add(path);
                    }
                    else{
                        hs.add(path);
                        ans+=5;
                    }
                }
                sopln(ans);

            }
            out.flush();
        }catch (Exception e) {
            sopln(e.toString());
        }
    }
    
    public final static int d = 256;
    static int MOD = 1000000007;
    static long V = 0;
    static final float EPSILON = (float)0.01;
    static final double PI = Math.PI;
    private static BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
    private static PrintWriter out = new PrintWriter (new OutputStreamWriter (System.out));
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        char nextChar()
        {
            try {
                return (char) (br.read());
            }catch (IOException e){
                return '~';
            }
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    static void sop(Object o){out.print(o);}
    static double ceil(double d){
        return Math.ceil(d);
    }
    static double floor(double d){
        return Math.floor(d);
    }
    static double round(double d){
        return Math.round(d);
    }
    static void sopln(Object o){out.println(o);}
    static void printArray(char arr[]){
        for(char L:arr)
            sop(L+" ");
        sopln("");
    }
}