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.util.*;

public class A {

    static class Node {
        String val;
        HashSet<String> nodes;

        Node(int x, int y) {
            val = x + " " + y;
            nodes = new HashSet<>();
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int testCases = sc.nextInt();

        for (int t = 0; t < testCases; t++) {
            String str = sc.next();

            Node cur_node = new Node(0, 0);
            int x = 0;
            int y = 0;

            char c[] = str.toCharArray();
            int n = c.length;

            Map<String, Node> map = new HashMap<>();

            int count = 0;

            map.put(cur_node.val, cur_node);

            for (int i = 0; i < n; i++) {
                char cur = c[i];

                String togo = "";

                if (cur == 'N') {
                    x++;
                    togo = x + " " + y;
                } else if (cur == 'S') {
                    x--;
                    togo = x + " " + y;
                } else if (cur == 'E') {
                    y++;
                    togo = x + " " + y;
                } else {
                    y--;
                    togo = x + " " + y;
                }

                if (cur_node.nodes.contains(togo)) {
                    count = count + 1;
                    cur_node = map.get(togo);
                } else {
                    count = count + 5;

                    Node node = null;

                    if (map.containsKey(togo)) {
                        node = map.get(togo);
                    } else {
                        node = new Node(x, y);
                        map.put(togo, node);
                    }

                    node.nodes.add(cur_node.val);

                    cur_node.nodes.add(togo);
                    cur_node = node;

                }

            }

            sb.append(count).append("\n");
        }

        System.out.print(sb);
    }
}