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 \le t \le 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

Starter code:

Solutions:
DIR = {"N": (0, 1), "S": (0, -1), "W": (-1, 0), "E": (1, 0)}

for t in range(int(input())):
   path = input()
   tracks = set()
   x, y = 0, 0
   time = 0
   for char in path:
      x1 = x + DIR[char][0]
      y1 = y + DIR[char][1]
      if (x, y, x1, y1) in tracks or (x1, y1, x, y) in tracks:
         time += 1
      else:
         time += 5
         tracks.add((x, y, x1, y1))
      x, y = x1, y1
   print(time)


import sys
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

t, = I()
while t:
    t -= 1
    s = input()
    x, y = 0, 0
    d = {'N': [0, 1], 'S': [0, -1], 'E': [1, 0], 'W': [-1, 0]}
    ans = 0
    v = dd(int)
    for i in s:
        a, b = x + d[i][0], y + d[i][1]
        if (x, y, a, b) in v:
            ans += 1
        else:
            ans += 5
        v[(x, y, a, b)] = v[(a, b, x, y)] = 1
        x, y = a, b
    print(ans)

def read_int():
    return int(input())


def read_ints():
    return list(map(int, input().split(' ')))


t = read_int()
for case_num in range(t):
    path = input()
    pos = (0, 0)
    ans = 0
    use = set()
    d = {'N': (0, 1), 'S': (0, -1), 'W': (-1, 0), 'E': (1, 0)}
    for c in path:
        ci, cj = pos
        di, dj = d[c]
        ni, nj = ci + di, cj + dj
        pos = (ni, nj)
        if ((ci, cj), (ni, nj)) in use:
            ans += 1
        else:
            ans += 5
            use.add(((ci, cj), (ni, nj)))
            use.add(((ni, nj), (ci, cj)))
    print(ans)


t=int(input())
for _ in range(t):
    s=input()
    aa={}
    i=0
    j=0
    ans=0
    for k in s:
        if(k=="N"):
            try:
                x=aa[((i,j),(i,j-1))]
                ans+=1
            except:
                ans+=5
                aa[((i,j),(i,j-1))]=1
            j-=1
                
        elif(k=="E"):
            try:
                x=aa[((i+1,j),(i,j))]
                ans+=1
            except:
                ans+=5
                aa[((i+1,j),(i,j))]=1
            i+=1
        elif(k=="W"):
            try:
                x=aa[((i,j),(i-1,j))]
                ans+=1
            except:
                ans+=5
                aa[((i,j),(i-1,j))]=1
            i-=1
        else:
            try:
                x=aa[((i,j+1),(i,j))]
                ans+=1
            except:
                ans+=5
                aa[((i,j+1),(i,j))]=1
            j+=1
    print(ans)
    
            
        
         
    


dir = {
    'N': (0, 1),
    'E': (1, 0),
    'W': (-1, 0),
    'S': (0, -1),
}

for tc in range(int(input())):
    cur, ans, vis = (0, 0), 0, set()
    for c in input():
        nxt = (cur[0] + dir[c][0], cur[1] + dir[c][1])

        if (cur, nxt) in vis:
            ans += 1
        else:
            ans += 5
            vis.add((cur, nxt))
            vis.add((nxt, cur))
        cur = nxt

    print(ans)


t=int(input())
for tests in range(t):
    S=input().strip()
    ANS=0
    Already=set()
    X=0
    Y=0
    
    for s in S:
        if s=="N":
            if (X,Y,X,Y+1) in Already:
                ANS+=1
            else:
                ANS+=5
            Already.add((X,Y,X,Y+1))
            Already.add((X,Y+1,X,Y))
            Y+=1
        elif s=="S":
            if (X,Y,X,Y-1) in Already:
                ANS+=1
            else:
                ANS+=5
            Already.add((X,Y,X,Y-1))
            Already.add((X,Y-1,X,Y))
            Y-=1
        elif s=="W":
            if (X,Y,X-1,Y) in Already:
                ANS+=1
            else:
                ANS+=5
            Already.add((X,Y,X-1,Y))
            Already.add((X-1,Y,X,Y))
            X-=1
        else:
            if (X,Y,X+1,Y) in Already:
                ANS+=1
            else:
                ANS+=5
            Already.add((X,Y,X+1,Y))
            Already.add((X+1,Y,X,Y))
            X+=1

    print(ANS)
        


for _ in range(int(input())):
    s = input()
    se = set()
    total = 0
    curr = [0, 0]
    for e in s:
        seg = ()
        if e == "E":
            seg = (curr[0], curr[1], 0)
            curr[0] += 1
        elif e == "N":
            seg = (curr[0], curr[1], 1)
            curr[1] += 1
        elif e == "W":
            seg = (curr[0]-1, curr[1], 0)
            curr[0] -= 1
        elif e == "S":
            seg = (curr[0], curr[1]-1, 1)
            curr[1] -= 1
        
        if seg in se:
            total += 1
        else:
            total += 5
            se.add(seg)
    print(total)

def list_int(): return list(map(int, input().split()))
def int_in(): return int(input())
def map_in(): return list(map(int, input().split()))
def list_in(): return input().split()

t=int_in()
for _ in range(t):
    v=set()
    s=input()
    x=0
    y=0
    c=0
    for i in s:
        #print(v, x, y, i)
        if i=='N':
            if (x,y,x+1,y) in v:
                c+=1
            elif (x+1,y, x,y) in v:
                c+=1
            else:
                c+=5
            v.add((x,y,x+1,y))
            x+=1
        elif i=='S':
            if (x,y,x-1,y) in v:
                c+=1
            elif (x-1,y, x,y) in v:
                c+=1
            else:
                c+=5
            v.add((x,y,x-1,y))
            x-=1
        elif i=='W':
            if (x,y,x,y+1) in v:
                c+=1
            elif (x, y+1, x,y) in v:
                c+=1
            else:
                c+=5
            v.add((x,y,x,y+1))
            y+=1
        else:
            if (x,y,x,y-1) in v:
                c+=1
            elif (x, y-1, x,y) in v:
                c+=1
            else:
                c+=5
            v.add((x,y,x,y-1))
            y-=1
    print(c)


import sys
import heapq as hq

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: list(map(int, readline().split()))
nl = lambda: list(map(int, readline().split()))

# eps = 10**-7

def solve():
    s = ns()
    d = dict()
    cnt = 0
    g = [(0, 1), (1, 0), (-1, 0), (0, -1)]
    cur = (0, 0)
    d[cur] = ''
    for x in s:
        for i in range(4):
            if x == 'NEWS'[i]:
                nx = (cur[0] + g[i][0], cur[1] + g[i][1])
                if nx in d and x in d[cur]:
                    cnt += 1
                else:
                    cnt += 5
                    if nx not in d:
                        d[nx] = ''
                    d[nx] += 'NEWS'[3-i]
                    d[cur] += x
                cur = nx
                break
    print(cnt)


# solve()

T = ni()
for _ in range(T):
    solve()


for __ in range(int(input())):
	s=input()
	x=0
	y=0
	ans=0
	d={}
	for i in range(len(s)):
		if(s[i]=='N'):
			if(d.get((x,y,x,y+1))==None):
				ans+=5
				d[(x,y,x,y+1)]=1
				d[(x,y+1,x,y)]=1
			else:
				ans+=1
			y=y+1
		elif(s[i]=='S'):
			if(d.get((x,y,x,y-1))==None):
				ans+=5
				d[(x,y,x,y-1)]=1
				d[(x,y-1,x,y)]=1
			else:
				ans+=1
			y=y-1
		elif(s[i]=='W'):
			if(d.get((x,y,x-1,y))==None):
				ans+=5
				d[(x,y,x-1,y)]=1
				d[(x-1,y,x,y)]=1
			else:
				ans+=1
			x=x-1
		else:
			if(d.get((x,y,x+1,y))==None):
				ans+=5
				d[(x,y,x+1,y)]=1
				d[(x+1,y,x,y)]=1
			else:
				ans+=1
			x=x+1
	print(ans)

# alpha = "abcdefghijklmnopqrstuvwxyz"
# prime = 1000000007#998244353 
# INF = 10000

# from sys import stdout
# from heapq import heappush, heappop
# from collections import defaultdict
# from collections import deque 
# import bisect 

# from math import sqrt    
# from math import gcd
# from math import log2

# with open('input.in','r') as Reader:
#     with open('output.out','w') as out:
        # n = int(Reader.readline())

    
# print(len(arr))
# print(arr[:10])


t = int(input())
for test in range(t):
    # n = int(input())
    # n, m = list(map(int, input().split()))
    # n2, m2 = list(map(int, input().split()))
    s = input()
    v = set()
    start = 0
    ans = 0
    cur = [0, 0, 0, 0]
    for i in s:
        if i=="N":
            cur[2] += 1
        elif i=="S":
            cur[2] -= 1
        elif i == "E":
            cur[3] += 1
        else:
            cur[3] -= 1

        key1 = str(cur)
        key2 = str([cur[2],cur[3], cur[0], cur[1]])
        if key1 in v:
            ans += 1
        else:
            ans += 5
        
        v.add(key1)
        v.add(key2)

        cur[0] = cur[2]
        cur[1] = cur[3]
    print(ans)

def new_pos(pos, step):
	if step == "N":
		pos = pos[0], pos[1] + 1
	elif step == "S":
		pos = pos[0], pos[1] -1
	elif step == "W":
		pos = pos[0] + 1, pos[1]
	else:
		pos = pos[0] -1, pos[1]
	return pos


t = int(input())
for _ in range(t):
	ans = 0
	s = input()
	used_hor = set()
	used_ver = set()

	pos = (0, 0)
	n = len(s)
	for i in range(n):
		next_st = new_pos(pos, s[i])
		way = (min(pos[0], next_st[0]), min(pos[1], next_st[1]))

		if s[i] == "N" or s[i] == "S":
			if way in used_ver:
				ans += 1
			else:
				ans += 5
			used_ver.add(way)
		else:
			if way in used_hor:
				ans += 1
			else:
				ans += 5
			used_hor.add(way)
		pos = next_st
		# print("used_hor", used_hor)
		# print("used_ver", used_ver)
	print(ans)


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

for _ in range(INT()):
    S = input()

    se = set()
    h = w = 0
    ans = 0
    for s in S:
        prev = (h, w)
        if s == 'S':
            h += 1
        elif s == 'N':
            h -= 1
        elif s == 'W':
            w -= 1
        else:
            w += 1
        cur = (h, w)
        key = (min(prev, cur), max(prev, cur))
        if key in se:
            ans += 1
        else:
            ans += 5
            se.add(key)
    print(ans)


t = int(input())
d = {'E': (1, 0), 'W':(-1, 0), 'N':(0, 1), 'S':(0, -1)}
for _ in range(t):
    s = input()
    time = 0
    met = set()
    x = y = 0
    for c in s:
        dx, dy = d[c]
        xx = x + dx
        yy = y + dy
        if (x, y, xx, yy) in met or (xx, yy, x, y) in met:
            time += 1
        else:
            time += 5
            met.add((x, y, xx, yy))
        x = xx
        y = yy
    print(time)

import sys,bisect,string,math,time,functools,random
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,init=True):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            self.stdin(inp_size)
        return

    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return

    def __str__(self):
        return  str(self.edges)

    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v

    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]

class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1

        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][r-(1<<N)])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][r-(1<<N)]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][r-(1<<N)]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])
        
    def print(self):
        for i in self.table:
            print(*i)

show_flg=False
show_flg=True
ans=0
D='EWNS'
m=[(1,0),(-1,0),(0,1),(0,-1)]
dc=dict(zip(D,m))

T=I()
for _ in range(T):
    ans=0
    s=input()
    N=len(s)*2+5
    x,y=(N,N)
    p=x*N+y
    f=dict()
    for i in s:
        dx,dy=dc[i]
        nx=x+dx
        ny=y+dy
        X=min(x,nx)
        Y=min(y,ny)
        p=X*N+Y
        p*=1 if dx==0 else -1
        if p in f:
            ans+=1
        else:
            ans+=5
        
        f[p]=1
        x,y=nx,ny
        #show(x-N,y-N,p,ans,f,N)
    
    
    print(ans)



t=int(input())
def an(x):
    if x=='S':
        return 'N'
    if x=='N':
        return 'S'
    if x=='W':
        return 'E'
    if x=='E':
        return 'W'
def mov(x,y):
    if y=='S':
        return (x[0]+1,x[1])
    if y=='N':
        return (x[0]-1,x[1])
    if y=='W':
        return (x[0],x[1]+1)
    if y=='E':
        return (x[0],x[1]-1)
while t>0:
    t-=1
    li={}
    s=input()
    at=(0,0)
    ans=0
    for i in s:
        nx=mov(at,i)
        if li.get((at,i),False):
            ans+=1
        else:
            ans+=5
            li[(at,i)]=True
            li[(nx,an(i))]=True
        at=nx
    print(ans)


rilist = lambda :[int(i) for  i  in  input().split()]
rlist = lambda :[i for  i  in  input().split()]
rint = lambda: int(input())
rfloat = lambda: float(input())
def pmat(mat):
    for i in range(len(mat)):
        a = ' '.join(map(str, mat[i]))
        print(a)
    print()

d = {'N':(1,0),'S':(-1,0),'E':(0,1),'W':(0,-1)}
def solve(t):
    path = input()
    curr = (0, 0)
    tmp = {}
    res = 0
    for p in path:
        a,b = d[p]
        next = (curr[0]+a,curr[1]+b)
        key = sorted((curr, next), key=lambda x:x[0])
        key = sorted(key, key=lambda x:x[1])
        key = tuple(key)
        curr = next
        res += tmp.get( key ,5)
        tmp[key]=1
    print(res)
test = int(input())
for tc in range(test):
    solve(tc+1)

t = int(input())
for _ in range(t):
    crd = set()
    path = input()
    x,y = 0,0
    sum = 0
    for c in path:
        if c=='N':
            if (x,y-1,x,y) in crd:
                sum += 1
            elif (x,y,x,y-1) in crd:
                sum += 1
            else:
                crd.add((x,y-1, x, y))
                sum += 5
            x,y=x,y-1
        elif c == 'S':
            if (x,y+1,x,y) in crd:
                sum += 1
            elif (x,y,x,y+1) in crd:
                sum += 1
            else:
                crd.add((x,y+1, x, y))
                sum += 5
            x,y=x,y+1
        elif c=='W':
            if (x+1,y,x,y) in crd:
                sum += 1
            elif (x,y,x+1,y) in crd:
                sum += 1
            else:
                crd.add((x+1,y, x, y))
                sum += 5
            x,y=x+1,y
        elif c=='E':
            if (x-1,y,x,y) in crd:
                sum += 1
            elif (x,y,x-1,y) in crd:
                sum += 1
            else:
                crd.add((x-1,y, x, y))
                sum += 5
            x,y = x-1,y
    print(sum)

from sys import stdin, exit
input = stdin.readline

def i(): return input()
def ii(): return int(input())
def iis(): return list(map(int, input().split()))
def liis():	return list(map(int, input().split()))
def print_array(a): print(" ".join(map(str, a)))

t = ii()
for _ in range(t):
	time = 0	
	x, y = 0, 0
	visited = set()
	s = input()
	for i in s:
		old_x = x
		old_y = y
		if i == 'N': y += 1
		elif i == 'S': y -= 1
		elif i == 'E': x += 1
		elif i == 'W': x -= 1
		else: continue	
		if (old_x, old_y, x, y) in visited:
			time += 1
		else:
			time += 5
	
		visited.add((x, y, old_x, old_y))
		visited.add((old_x, old_y, x, y))
	
	print(time)


t = int(input())
for _ in range(t):
    s = input()
    st = set()
    x, y = 0, 0
    ans = 0
    for c in s:
        if c == 'S':
            if (x, y + 1) in st:
                ans += 1
            else:
                ans += 5
                st.add((x, y + 1))
            y += 2
        elif c == 'N':
            if (x, y - 1) in st:
                ans += 1
            else:
                ans += 5
                st.add((x, y - 1))
            y -= 2
        elif c == 'W':
            if (x + 1, y) in st:
                ans += 1
            else:
                ans += 5
                st.add((x + 1, y))
            x += 2
        else:
            if (x - 1, y) in st:
                ans += 1
            else:
                ans += 5
                st.add((x - 1, y))
            x -= 2
    print(ans)


from math import *

for zz in range(int(input())):
    used = set()
    ans = 0
    pos = [0, 0]
    a = 0
    for i in range(35000):
        a += 1
    a = ans - 1
    for x in input():
        ppos = pos[:]
        ppos = tuple(ppos)
        if x == 'N':
            pos[0] += 1
        elif x == 'S':
            pos[0] -= 1
        elif x == 'W':
            pos[1] -= 1
        else:
            pos[1] += 1
        if ((ppos, tuple(pos)) in used) or ((tuple(pos), ppos) in used):
            ans += 1
        else:
            used.add((ppos, tuple(pos)))
            ans += 5
    print(ans)

#aaa


import time
import sys
readline = sys.stdin.readline

t = time.time()
d = {'N': -10**9, 'S': 10**9, 'E': 1, 'W': -1}
for _ in range(int(input())):
    s = readline().rstrip()
    pos = 0
    visited = set()
    dist = 0
    for c in s:
        dest = pos + d[c]
        dist += 1 if (pos, dest) in visited or (dest, pos) in visited else 5
        visited.update(((pos, dest), (dest, pos)))
        pos = dest

    print(dist)

while time.time() - t < 0.9:
    pass