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 com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.io.*;
import java.util.*;

public class C {
    static int counter;

    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int t = scn.nextInt();
        scn.nextLine();
        while (t-- > 0) {
            char c[] = scn.nextLine().toCharArray();
            HashMap<Integer, HashMap<Integer, Integer>> map = new HashMap<>();
            map.put(0, new HashMap<>());
            map.get(0).put(0, 0);
            counter = 1;
            int x = 0;
            int y = 0;
            ArrayList<Integer> ar = new ArrayList<>();
            ar.add(0);
            for (int i = 0; i < c.length; ++i) {
                if (c[i] == 'N') {
                    y++;
                    updateMap(map, x, y, ar);
                } else if (c[i] == 'W') {
                    x--;
                    updateMap(map, x, y, ar);
                } else if (c[i] == 'E') {
                    x++;
                    updateMap(map, x, y, ar);
                } else {
                    y--;
                    updateMap(map, x, y, ar);
                }
            }
            long ans = 0;
            HashMap<Integer, HashSet<Integer>> visited = new HashMap<>();
            for (int no : ar) {
                visited.put(no, new HashSet<>());
            }
            for (int i = 0, j = 1; j < ar.size(); ++j, ++i) {
                int start = ar.get(i);
                int end = ar.get(j);
                if (visited.get(start).contains(end)) {
                    ans++;
                } else {
                    visited.get(start).add(end);
                    visited.get(end).add(start);
                    ans += 5;
                }
            }
            System.out.println(ans);
        }

    }


    private static void updateMap(HashMap<Integer, HashMap<Integer, Integer>> map, int x, int y, ArrayList<Integer> ar) {
        if (map.containsKey(x)) {
            if (map.get(x).containsKey(y)) {
                ar.add(map.get(x).get(y));
            } else {
                map.get(x).put(y, counter);
                ar.add(counter);
                counter++;
            }
        } else {
            map.put(x, new HashMap<>());
            map.get(x).put(y, counter);
            ar.add(counter);
            counter++;
        }
    }
}

/*46

52

17

21
*/
