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

Difficulty: MEDIUM
Tags: Data structures

Implementation
Skill types: Data structures

Starter code:

Solutions:
import sys, math, cmath, time
start_time = time.time()
tt = 0

def inp():
	return int(input())

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

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def solve():
	a = insr()
	q = dict()
	c = 0
	(x, y) = (0, 0)
	for i in range(len(a)):
		w = str(x) + ' ' + str(y)
		if a[i] == 'N':
			y = y + 1
		if a[i] == 'S':
			y = y - 1
		if a[i] == 'E':
			x = x + 1
		if a[i] == 'W':
			x = x - 1
		if q.get(w + ' ' + str(x) + ' ' + str(y)):
			c = c + 1
		else:
			c = c + 5
		q[w + ' ' + str(x) + ' ' + str(y)] = 1
		q[str(x) + ' ' + str(y) + ' ' + w] = 1
	print(c)

def main():
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
for _ in range(t):
	s = input()
	x = 0
	y = 0
	D = {}
	ans = 0
	for i in range(len(s)):
		c_x = x
		c_y = y
		if s[i] == 'N':
			c_y = y + 1
		if s[i] == 'S':
			c_y = y - 1
		if s[i] == 'W':
			c_x = x - 1
		if s[i] == 'E':
			c_x = x + 1
		if (x, y, c_x, c_y) in D:
			ans += 1
		else:
			D[x, y, c_x, c_y] = 1
			D[c_x, c_y, x, y] = 1
			ans += 5
		x = c_x
		y = c_y
	print(ans)


for _ in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	b = {}
	k = 0
	for i in s:
		(x1, y1) = (x, y)
		if i == 'N':
			y = y + 1
		elif i == 'S':
			y = y - 1
		elif i == 'E':
			x = x + 1
		else:
			x = x - 1
		if (x, y, x1, y1) in b or (x1, y1, x, y) in b:
			k = k + 1
		else:
			k = k + 5
			b[x1, y1, x, y] = 1
	print(k)


for _ in range(int(input())):
	path = input()
	track = {}
	track[0, 0] = [0, 0, 0, 0]
	coordinate = (0, 0)
	time = 0
	for p in path:
		if p == 'N':
			if track[coordinate][0] == 1:
				time += 1
			else:
				time += 5
				track[coordinate][0] = 1
			t1 = coordinate[0]
			t2 = coordinate[1] + 1
			coordinate = (t1, t2)
			if coordinate in track.keys():
				track[coordinate][2] = 1
			else:
				track[coordinate] = [0, 0, 1, 0]
		elif p == 'S':
			if track[coordinate][2] == 1:
				time += 1
			else:
				time += 5
				track[coordinate][2] = 1
			t1 = coordinate[0]
			t2 = coordinate[1] - 1
			coordinate = (t1, t2)
			if coordinate in track.keys():
				track[coordinate][0] = 1
			else:
				track[coordinate] = [1, 0, 0, 0]
		elif p == 'E':
			if track[coordinate][1] == 1:
				time += 1
			else:
				time += 5
				track[coordinate][1] = 1
			t1 = coordinate[0] + 1
			t2 = coordinate[1]
			coordinate = (t1, t2)
			if coordinate in track.keys():
				track[coordinate][3] = 1
			else:
				track[coordinate] = [0, 0, 0, 1]
		else:
			if track[coordinate][3] == 1:
				time += 1
			else:
				time += 5
				track[coordinate][3] = 1
			t1 = coordinate[0] - 1
			t2 = coordinate[1]
			coordinate = (t1, t2)
			if coordinate in track.keys():
				track[coordinate][1] = 1
			else:
				track[coordinate] = [0, 1, 0, 0]
	print(time)


for i in range(int(input())):
	x1 = x2 = x3 = out = x4 = int(0)
	ans = set()
	for x in list(input()):
		if x == 'N':
			x3 -= 1
		elif x == 'S':
			x3 += 1
		elif x == 'E':
			x4 += 1
		elif x == 'W':
			x4 -= 1
		if (x1, x2, x3, x4) not in ans and (x3, x4, x1, x2) not in ans:
			out += 5
			ans.add((x1, x2, x3, x4))
			ans.add((x3, x4, x1, x2))
		else:
			out += 1
		x1 = x3
		x2 = x4
	print(out)


for ii in range(int(input())):
	s = input()
	dic = {}
	x = 0
	y = 0
	ans = 0
	dic[x, y] = 1
	for i in s:
		inix = x
		iniy = y
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'W':
			x -= 1
		elif i == 'E':
			x += 1
		if (inix, iniy, x, y) in dic:
			ans += 1
		else:
			dic[inix, iniy, x, y] = 1
			dic[x, y, inix, iniy] = 1
			ans += 5
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	d = {}
	xf = 0
	yf = 0
	xi = 0
	yi = 0
	ans = 0
	for i in input():
		if i == 'N':
			yf = yi + 1
		elif i == 'S':
			yf = yi - 1
		elif i == 'E':
			xf = 1 + xi
		else:
			xf = xi - 1
		if (xf, yf, xi, yi) in d or (xi, yi, xf, yf) in d:
			ans += 1
		else:
			d[xf, yf, xi, yi] = 1
			ans += 5
		xi = xf
		yi = yf
	print(ans)


d = {'N': (0, 1), 'S': (0, -1), 'W': (-1, 0), 'E': (1, 0)}
for _ in range(int(input())):
	vis = set()
	res = 0
	(x, y) = (0, 0)
	for v in input():
		(dx, dy) = d[v]
		k = (x, y, dy == 0) if dx + dy > 0 else (x + dx, y + dy, dy == 0)
		res += 1 if k in vis else 5
		vis.add(k)
		x += dx
		y += dy
	print(res)


for _ in range(int(input())):
	s = input()
	(mov, x, y, ans) = (set(), 0, 0, 0)
	for i in s:
		(tx, ty) = (x, y)
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		else:
			x -= 1
		if (min(x, tx), max(x, tx), min(y, ty), max(y, ty)) in mov:
			ans += 1
		else:
			ans += 5
			mov.add((min(x, tx), max(x, tx), min(y, ty), max(y, ty)))
	print(ans)


for nt in range(int(input())):
	s = input()
	o = [0, 0]
	v = {(0, 0): 0}
	ans = 0
	for i in s:
		p = tuple(o)
		if i == 'N':
			o[1] += 1
		elif i == 'S':
			o[1] -= 1
		elif i == 'W':
			o[0] -= 1
		else:
			o[0] += 1
		if p + tuple(o) in v or tuple(o) + p in v:
			ans += 1
		else:
			v[p + tuple(o)] = 0
			ans += 5
	print(ans)


for _ in range(int(input())):
	s = input()
	freq = {}
	prev = (0, 0)
	pres = prev
	c = 0
	for i in s:
		if i == 'N':
			pres = (prev[0] + 1, prev[1])
		elif i == 'S':
			pres = (prev[0] - 1, prev[1])
		elif i == 'E':
			pres = (prev[0], prev[1] + 1)
		else:
			pres = (prev[0], prev[1] - 1)
		x = (prev, pres)
		xrev = (pres, prev)
		if x in freq or xrev in freq:
			c += 1
		else:
			c += 5
			freq[x] = 1
		prev = pres
	print(c)


for case in range(int(input())):
	x1 = y1 = 0
	visited_path = set()
	time = 0
	path = input()
	for c in path:
		x0 = x1
		y0 = y1
		if c == 'W':
			x1 -= 1
		elif c == 'E':
			x1 += 1
		elif c == 'N':
			y1 += 1
		else:
			y1 -= 1
		A = (x0, y0)
		B = (x1, y1)
		if (A, B) not in visited_path or (B, A) not in visited_path:
			visited_path.add((A, B))
			visited_path.add((B, A))
			time += 5
		else:
			time += 1
	print(time)


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)


t = int(input())
for i in range(t):
	p = input()
	ar = {}
	ans = 0
	x = 0
	y = 0
	for i in range(len(p)):
		st = str(x) + str(y)
		x2 = str(x)
		y2 = str(y)
		if p[i] == 'N':
			y += 1
		if p[i] == 'S':
			y -= 1
		if p[i] == 'W':
			x -= 1
		if p[i] == 'E':
			x += 1
		st += str(x) + str(y)
		st2 = str(x) + str(y) + x2 + y2
		if st in ar:
			ans += 1
		else:
			ans += 5
		ar[st] = 1
		ar[st2] = 1
	print(ans)


t = int(input())
while t:
	t -= 1
	(ip, r, c, a, sa) = (input(), 0, 0, 0, set())
	for d in ip:
		if d == 'N':
			tm = (r, c, r, c + 1)
			c += 1
		elif d == 'S':
			tm = (r, c - 1, r, c)
			c -= 1
		elif d == 'W':
			tm = (r - 1, c, r, c)
			r -= 1
		elif d == 'E':
			tm = (r, c, r + 1, c)
			r += 1
		if tm not in sa:
			a += 5
			sa.add(tm)
		else:
			a += 1
	print(a)


T = int(input())
while T > 0:
	d = {}
	p = input().strip()
	(x, y) = (0, 0)
	ans = 0
	for c in p:
		if c == 'E':
			if d.get((x, y, c)):
				ans += 1
			else:
				ans += 5
				d[x, y, c] = True
				d[x, y + 1, 'W'] = True
			y += 1
		elif c == 'W':
			if d.get((x, y, c)):
				ans += 1
			else:
				ans += 5
				d[x, y, c] = True
				d[x, y - 1, 'E'] = True
			y -= 1
		elif c == 'N':
			if d.get((x, y, c)):
				ans += 1
			else:
				ans += 5
				d[x, y, c] = True
				d[x - 1, y, 'S'] = True
			x -= 1
		elif c == 'S':
			if d.get((x, y, c)):
				ans += 1
			else:
				ans += 5
				d[x, y, c] = True
				d[x + 1, y, 'N'] = True
			x += 1
	print(ans)
	T -= 1


n = int(input())
for i in range(n):
	s = input()
	visited = set()
	g = [[1, 0], [0, 1], [0, -1], [-1, 0]]
	start = [0, 0]
	ans = 0
	for k in s:
		pair1 = (start[0], start[1])
		if k == 'N':
			start[0] += g[0][0]
			start[1] += g[0][1]
		if k == 'S':
			start[0] += g[3][0]
			start[1] += g[3][1]
		if k == 'E':
			start[0] += g[1][0]
			start[1] += g[1][1]
		if k == 'W':
			start[0] += g[2][0]
			start[1] += g[2][1]
		pair2 = (start[0], start[1])
		pair = ((pair2[0] + pair1[0]) / 2, (pair2[1] + pair1[1]) / 2)
		if pair not in visited:
			visited.add(pair)
			ans += 5
		else:
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	s = input()
	ans = 0
	path = set()
	(x1, y1, x2, y2) = (0, 0, 0, 0)
	ans = 0
	for i in s:
		x1 = x2
		y1 = y2
		if i == 'N':
			y2 += 1
		elif i == 'S':
			y2 -= 1
		elif i == 'E':
			x2 += 1
		elif i == 'W':
			x2 -= 1
		p1 = str(x1) + ' ' + str(y1) + ' ' + str(x2) + ' ' + str(y2)
		p2 = str(x2) + ' ' + str(y2) + ' ' + str(x1) + ' ' + str(y1)
		if p1 in path or p2 in path:
			ans += 1
		else:
			ans += 5
			path.add(p1)
	print(ans)


def f(s):
	travel = set()
	pos = [0, 0]
	for i in s:
		if i == 'N':
			travel.add(1000000 * pos[0] + pos[1] + 1 / 2)
			pos[1] += 1
		elif i == 'S':
			travel.add(1000000 * pos[0] + pos[1] - 1 / 2)
			pos[1] -= 1
		elif i == 'E':
			travel.add(1000000 * pos[0] + 500000 + pos[1])
			pos[0] += 1
		else:
			travel.add(1000000 * pos[0] - 500000 + pos[1])
			pos[0] -= 1
	x = len(s)
	y = len(travel)
	return x + 4 * y
for i in range(int(input())):
	print(f(input()))


t = int(input())
for _ in range(t):
	d = {}
	ans = 0
	y = 0
	x = 0
	for i in input():
		(dy, dx) = (0, 0)
		if i == 'N':
			dy = -1
		elif i == 'S':
			dy = 1
		elif i == 'W':
			dx = -1
		else:
			dx = 1
		ny = y + dy
		nx = x + dx
		a = (y, x)
		b = (ny, nx)
		if a > b:
			(a, b) = (b, a)
		if (a, b) in d.keys():
			ans += 1
		else:
			ans += 5
		d[a, b] = 1
		(y, x) = (ny, nx)
	print(ans)


for _ in range(int(input())):
	gh = input().rstrip()
	n = len(gh)
	n += 1
	ct = 0
	vis = dict()
	n -= 1
	x = n
	y = n
	a = n
	b = n
	for i in range(n):
		if gh[i] == 'N':
			b = b + 1
		if gh[i] == 'S':
			b = b - 1
		if gh[i] == 'E':
			a = a - 1
		if gh[i] == 'W':
			a = a + 1
		if (a, b, x, y) not in vis:
			vis[a, b, x, y] = 1
			vis[x, y, a, b] = 1
			ct += 5
		else:
			ct += 1
		x = a
		y = b
	print(ct)


def solve_test_case(t):
	s = str(input())
	pos = (0, 0)
	t = 0
	paths_performed_past = set()
	for i in range(len(s)):
		action = s[i]
		if action == 'N':
			diff = (1, 0)
		elif action == 'S':
			diff = (-1, 0)
		elif action == 'E':
			diff = (0, 1)
		else:
			diff = (0, -1)
		new_pos = (pos[0] + diff[0], pos[1] + diff[1])
		elt = (pos, new_pos)
		if (pos, new_pos) in paths_performed_past or (new_pos, pos) in paths_performed_past:
			t += 1
		else:
			paths_performed_past.add(elt)
			t += 5
		pos = new_pos
	print(t)

def parse_array(f):
	return list(map(f, input().split()))

def solve():
	T = int(input())
	for t in range(T):
		solve_test_case(t)
solve()


a = int(input())
for _ in range(a):
	l1 = list()
	l1 = list(map(str, input().strip().split()))
	path = l1[0]
	f = set([])
	cntA = 0
	cntB = 0
	ans = 0
	for x in range(len(path)):
		i = cntA
		j = cntB
		if path[x] == 'N':
			cntA += 1
		elif path[x] == 'S':
			cntA -= 1
		elif path[x] == 'W':
			cntB -= 1
		elif path[x] == 'E':
			cntB += 1
		if ((cntA + i) / 5, (cntB + j) / 5) in f:
			ans = ans + 1
		else:
			f.add(((cntA + i) / 5, (cntB + j) / 5))
			ans = ans + 5
	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 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)


import sys
input = sys.stdin.readline
t_ = int(input())
while t_:
	t_ -= 1
	s = input().strip()
	(x, y, t) = (0, 0, 0)
	paths = set()
	for i in s:
		(px, py) = (x, y)
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		else:
			x -= 1
		if (px, py, x, y) in paths or (x, y, px, py) in paths:
			t += 1
		else:
			t += 5
			paths.add((px, py, x, y))
	print(t)


import sys
import math
from collections import defaultdict

def solve(test):
	s = input()
	(up, down, left, right) = (0, 0, 0, 0)
	ans = 0
	rec = {}
	(hor, ver) = (0, 0)
	for i in s:
		og = (hor, ver)
		if i == 'N':
			ver += 1
		elif i == 'S':
			ver -= 1
		elif i == 'E':
			hor += 1
		else:
			hor -= 1
		if (hor, ver, og[0], og[1]) in rec:
			ans += 1
		else:
			rec[hor, ver, og[0], og[1]] = 1
			rec[og[0], og[1], hor, ver] = 1
			ans += 5
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


t = int(input())
for _ in range(t):
	(i, j) = (0, 0)
	visited = set()
	r = 0
	path = list(input())
	for p in path:
		(ci, cj) = (i, j)
		if p == 'N':
			j += 1
		elif p == 'W':
			i -= 1
		elif p == 'S':
			j -= 1
		elif p == 'E':
			i += 1
		tempx = (i + ci) / 2
		tempy = (j + cj) / 2
		if (tempx, tempy) in visited:
			r += 1
		else:
			r += 5
			visited.add((tempx, tempy))
	print(r)


def solve():
	a = input()
	x = 0
	y = 0
	W = set()
	ans = 0
	for i in range(len(a)):
		px = x
		py = y
		if a[i] == 'W':
			x -= 1
		if a[i] == 'E':
			x += 1
		if a[i] == 'S':
			y -= 1
		if a[i] == 'N':
			y += 1
		par1 = (px, py)
		par2 = (x, y)
		if par1 < par2:
			(par1, par2) = (par2, par1)
		par3 = (par1, par2)
		if par3 in W:
			ans += 1
		else:
			ans += 5
		W.add(par3)
	print(ans)
t = int(input())
while t > 0:
	solve()
	t -= 1


import sys
input = sys.stdin.readline

def main():
	d = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
	t = int(input())
	for _ in range(t):
		S = input().strip()
		ans = 0
		roads = set()
		p = [0, 0]
		for s in S:
			(x, y) = p
			(dx, dy) = d[s]
			q = (x, y, x + dx, y + dy)
			r = (x + dx, y + dy, x, y)
			if q in roads or r in roads:
				ans += 1
			else:
				ans += 5
				roads.add((x, y, x + dx, y + dy))
			p[0] += dx
			p[1] += dy
		sys.stdout.write(str(ans) + '\n')
main()


t = int(input())
for i in range(t):
	s = input()
	adj = [(0, 1), (1, 0), (-1, 0), (0, -1)]
	d = {'N': 0, 'S': 3, 'W': 2, 'E': 1}
	seen = set()
	time = 0
	(x, y) = (0, 0)
	for i in s:
		(nx, ny) = (adj[d[i]][0] + x, adj[d[i]][1] + y)
		if (x, y, nx, ny) in seen or (nx, ny, x, y) in seen:
			time += 1
		else:
			time += 5
			seen.add((x, y, nx, ny))
		(x, y) = (nx, ny)
	print(time)


class path(object):

	def __init__(self, beg, end):
		self.p = {beg, end}
t = int(input())
for i in range(0, t):
	cost = 0
	x = list(input())
	road = {None}
	curr_x = 0
	curr_y = 0
	prv = (0, 0)
	for j in range(0, len(x)):
		px = 0
		py = 0
		if x[j] == 'N':
			py += 1
		elif x[j] == 'S':
			py -= 1
		elif x[j] == 'W':
			px -= 1
		else:
			px += 1
		curr_x += px
		curr_y += py
		temp = (curr_x, curr_y)
		temp_path = frozenset({prv, temp})
		if temp_path in road:
			cost += 1
		else:
			road.add(temp_path)
			cost += 5
		prv = temp
	print(cost)


h = 7 ** 6
for s in [*open(0)][1:]:
	r = x = 0
	d = {}
	for c in s[:-1]:
		i = 'SNWE'.find(c)
		y = x + (1, -1, h, -h)[i]
		p = (x | y, x & y)
		x = y
		r += d.get(p, 5)
		d[p] = 1
	print(r)


tc = int(input())
for _ in range(tc):
	a = input()
	setp = set()
	x = y = ans = nx = ny = 0
	for c in a:
		if c == 'N':
			nx = x + 1
		if c == 'S':
			nx = x - 1
		if c == 'E':
			ny = y + 1
		if c == 'W':
			ny = y - 1
		if (x, y, nx, ny) in setp or (nx, ny, x, y) in setp:
			ans += 1
		else:
			ans += 5
			setp.add((x, y, nx, ny))
		x = nx
		y = ny
	print(ans)


t = int(input())
for tt in range(0, t):
	direction = input()
	(x, y) = (0, 0)
	path = 0
	l = set()
	for d in direction:
		if d == 'N':
			x += 1
			toappend = (x - 1, y, x, y)
			ttoappend = (x, y, x - 1, y)
		elif d == 'S':
			x -= 1
			toappend = (x + 1, y, x, y)
			ttoappend = (x, y, x + 1, y)
		elif d == 'E':
			y += 1
			toappend = (x, y - 1, x, y)
			ttoappend = (x, y, x, y - 1)
		elif d == 'W':
			y -= 1
			toappend = (x, y + 1, x, y)
			ttoappend = (x, y, x, y + 1)
		if toappend not in l or ttoappend not in l:
			path += 5
			l.add(toappend)
			l.add(ttoappend)
		else:
			path += 1
	print(path)


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)


def timeReq(s):
	if s.count(s[0]) == len(s):
		print(len(s) * 5)
		return
	x = 0
	y = 0
	ans = 0
	positions = set()
	for i in range(len(s)):
		temp = (x, y)
		if s[i] == 'N':
			y += 1
		elif s[i] == 'S':
			y -= 1
		elif s[i] == 'W':
			x -= 1
		elif s[i] == 'E':
			x += 1
		if (temp, (x, y)) in positions:
			ans += 1
		else:
			ans += 5
		positions.add((temp, (x, y)))
		positions.add(((x, y), temp))
	print(ans)

def main():
	t = int(input())
	for i in range(t):
		timeReq(input())
main()


def solve(s):
	visited = set()
	time = 0
	i_x = 0
	i_y = 0
	x = 0
	y = 0
	for i in s:
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		elif i == 'W':
			x -= 1
		if (i_x, i_y, x, y) in visited or (x, y, i_x, i_y) in visited:
			time += 1
		else:
			visited.add((i_x, i_y, x, y))
			time += 5
		i_x = x
		i_y = y
	return time
t = int(input())
for i in range(t):
	s = input()
	print(solve(s))


for _ in range(int(input())):
	s = input()
	v = set()
	p = [0, 0]
	cnt = 0
	for i in s:
		last = p[:]
		if i == 'N':
			p[1] += 1
		elif i == 'S':
			p[1] -= 1
		elif i == 'E':
			p[0] += 1
		else:
			p[0] -= 1
		if (last[0], last[1], p[0], p[1]) in v or (p[0], p[1], last[0], last[1]) in v:
			cnt += 1
		else:
			cnt += 5
		v.add((last[0], last[1], p[0], p[1]))
		v.add((p[0], p[1], last[0], last[1]))
	print(cnt)


from sys import stdin, exit
input = stdin.readline

def i():
	return input()

def ii():
	return int(input())

def iis():
	return 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)


def main():
	t = int(input())
	while t:
		t -= 1
		path = input()
		(x, y) = (0, 0)
		pos = set()
		time = 0
		for p in path:
			u = (x, y)
			if p == 'N':
				y += 1
			elif p == 'S':
				y -= 1
			elif p == 'W':
				x += 1
			else:
				x -= 1
			v = (x, y)
			if (u, v) in pos:
				time += 1
			else:
				time += 5
				pos.add((u, v))
				pos.add((v, u))
		print(time)
main()


for _ in range(int(input())):
	a = {}
	s = input()
	x = 0
	y = 0
	ans = 0
	for c in s:
		prevx = x
		prevy = y
		if c == 'N':
			x += 1
		elif c == 'S':
			x -= 1
		elif c == 'W':
			y -= 1
		else:
			y += 1
		if prevx > x:
			d = 0
			dd = 1
		elif prevx < x:
			d = 1
			dd = 0
		elif prevy > y:
			d = 2
			dd = 3
		else:
			d = 3
			dd = 2
		if 4 * (1000000 * x + y) + d in a.keys():
			ans += 1
		else:
			ans += 5
			a[4 * (1000000 * x + y) + d] = 1
			a[4 * (1000000 * prevx + prevy) + dd] = 1
	print(ans)


t = int(input())
for __ in range(t):
	dirs = input()
	(x, y) = (0, 0)
	visited_path = set()
	time = 0
	for movement in dirs:
		if movement == 'N':
			(new_x, new_y) = (x, y + 1)
		if movement == 'S':
			(new_x, new_y) = (x, y - 1)
		if movement == 'W':
			(new_x, new_y) = (x - 1, y)
		if movement == 'E':
			(new_x, new_y) = (x + 1, y)
		pair = [(x, y), (new_x, new_y)]
		pair.sort()
		pair = tuple(pair)
		if pair not in visited_path:
			time += 5
			visited_path.add(pair)
		else:
			time += 1
		(x, y) = (new_x, new_y)
	print(time)


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


from collections import defaultdict

def solve():
	dp = defaultdict(lambda : 5)
	string = input()
	ans = 0
	x = 0
	y = 0
	x1 = 0
	y1 = 0
	for char in string:
		if char == 'N':
			x1 += 1
		elif char == 'S':
			x1 -= 1
		elif char == 'E':
			y1 += 1
		else:
			y1 -= 1
		getValue = dp[x, y, x1, y1]
		ans += getValue
		if getValue == 5:
			dp[x, y, x1, y1] = 1
			dp[x1, y1, x, y] = 1
		x = x1
		y = y1
	return ans
t = int(input())
for i in range(t):
	print(solve())


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()))

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)
T = ni()
for _ in range(T):
	solve()


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

def int_in():
	return int(input())

def map_in():
	return 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:
		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)


N = int(input())
for _ in range(N):
	S = input()
	mp = set()
	(i, j) = (0, 0)
	total = 0
	for c in S:
		code = None
		if c == 'N':
			code = (i, j, 'v')
			i -= 1
		elif c == 'S':
			code = (i + 1, j, 'v')
			i += 1
		elif c == 'W':
			code = (i, j, 'h')
			j -= 1
		elif c == 'E':
			code = (i, j + 1, 'h')
			j += 1
		if code in mp:
			total += 1
		else:
			total += 5
			mp.add(code)
	print(total)


import sys
input = sys.stdin.readline

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


h = 100050
for s in [*open(0)][1:]:
	r = x = 0
	d = {}
	for c in s[:-1]:
		y = x + (1, -1, -h, h)['SNWE'.find(c)]
		p = (x | y, x & y)
		x = y
		r += d.get(p, 5)
		d[p] = 1
	print(r)


import sys
sys.setrecursionlimit(10 ** 6)

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def SI():
	return sys.stdin.readline()[:-1]

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1

def MI1():
	return map(int1, sys.stdin.readline().split())

def LI1():
	return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep='\n')
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
	for _ in range(II()):
		s = SI()
		xx = set()
		yy = set()
		ans = 0
		(x, y) = (0, 0)
		for c in s:
			if c == 'N':
				if (x, y) in yy:
					ans += 1
				else:
					ans += 5
				yy.add((x, y))
				y += 1
			if c == 'S':
				y -= 1
				if (x, y) in yy:
					ans += 1
				else:
					ans += 5
				yy.add((x, y))
			if c == 'E':
				if (x, y) in xx:
					ans += 1
				else:
					ans += 5
				xx.add((x, y))
				x += 1
			if c == 'W':
				x -= 1
				if (x, y) in xx:
					ans += 1
				else:
					ans += 5
				xx.add((x, y))
		print(ans)
main()


t = int(input())
for _ in range(t):
	direcs = input()
	time = 0
	coords = (0, 0)
	visited = set()
	for i in direcs:
		path = (coords,)
		if i == 'N':
			t = list(coords)
			t[1] += 1
			coords = tuple(t)
		elif i == 'S':
			t = list(coords)
			t[1] -= 1
			coords = tuple(t)
		elif i == 'E':
			t = list(coords)
			t[0] += 1
			coords = tuple(t)
		else:
			t = list(coords)
			t[0] -= 1
			coords = tuple(t)
		path += (coords,)
		if path in visited:
			time += 1
		else:
			time += 5
			visited.add(path)
			visited.add((path[1], path[0]))
	print(time)


t = int(input())
for i in range(t):
	cost = 0
	s = input()
	pos = [0, 0]
	my_set = set()
	for i in s:
		temp = pos.copy()
		if i == 'N':
			pos[1] += 1
		if i == 'S':
			pos[1] -= 1
		if i == 'W':
			pos[0] -= 1
		if i == 'E':
			pos[0] += 1
		if str(pos + temp) in my_set or str(temp + pos) in my_set:
			cost += 1
		else:
			my_set.add(str(temp + pos))
			cost += 5
	print(cost)


def answer(t):
	for i in range(t):
		s = input()
		w = set()
		(x, y) = (0, 0)
		ti = 0
		for i in s:
			if i == 'N':
				if str(x) + str(y) + 'N' in w or str(x) + str(y + 1) + 'S' in w:
					ti += 1
				else:
					ti += 5
					w.add(str(x) + str(y) + 'N')
				y += 1
			elif i == 'S':
				if str(x) + str(y) + 'S' in w or str(x) + str(y - 1) + 'N' in w:
					ti += 1
				else:
					ti += 5
					w.add(str(x) + str(y) + 'S')
				y -= 1
			elif i == 'W':
				if str(x) + str(y) + 'W' in w or str(x - 1) + str(y) + 'E' in w:
					ti += 1
				else:
					ti += 5
					w.add(str(x) + str(y) + 'W')
				x -= 1
			elif i == 'E':
				if str(x) + str(y) + 'E' in w or str(x + 1) + str(y) + 'W' in w:
					ti += 1
				else:
					ti += 5
					w.add(str(x) + str(y) + 'E')
				x += 1
		print(ti)
answer(int(input()))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	x = y = 0
	d = {}
	ans = 0
	for i in input().rstrip('\n'):
		x1 = x
		y1 = y
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		else:
			x -= 1
		if (x, y, x1, y1) in d or (x1, y1, x, y) in d:
			ans += 1
		else:
			ans += 5
			d[x1, y1, x, y] = 1
	print(ans)


dire = {'N': 0, 'S': 1, 'E': 2, 'W': 3}
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
t = int(input())
for i in range(t):
	ans = 0
	s = input()
	dicti = {}
	x = 0
	y = 0
	for i in s:
		new_x = x + dx[dire[i]]
		new_y = y + dy[dire[i]]
		if (x, y, new_x, new_y) in dicti or (new_x, new_y, x, y) in dicti:
			ans += 1
		else:
			dicti[x, y, new_x, new_y] = 1
			dicti[new_x, new_y, x, y] = 1
			ans += 5
		x = new_x
		y = new_y
	print(ans)


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def change(X, Y, charac):
	if charac == 'N':
		Y += 1
	elif charac == 'S':
		Y -= 1
	elif charac == 'W':
		X -= 1
	else:
		X += 1
	return (X, Y)

def dashed(ch):
	if ch == 'N':
		chdash = 'S'
	elif ch == 'S':
		chdash = 'N'
	elif ch == 'E':
		chdash = 'W'
	else:
		chdash = 'E'
	return chdash
t = INT()
while t != 0:
	s = input()
	ans = 0
	dic = {}
	x = y = 0
	for ch in s:
		if (x, y) not in dic:
			ans += 5
			dic[x, y] = []
			dic[x, y].append(ch)
			(x, y) = change(x, y, ch)
			if (x, y) in dic:
				dic[x, y].append(dashed(ch))
			else:
				dic[x, y] = []
				dic[x, y].append(dashed(ch))
		elif ch in dic[x, y]:
			ans += 1
			(x, y) = change(x, y, ch)
		else:
			ans += 5
			dic[x, y].append(ch)
			(x, y) = change(x, y, ch)
			if (x, y) in dic:
				dic[x, y].append(dashed(ch))
			else:
				dic[x, y] = []
				dic[x, y].append(dashed(ch))
	print(ans)
	t -= 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	s = input().rstrip()
	visited = set()
	x = 0
	y = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == 'N':
			if (x, y, x, y + 1) in visited:
				ans += 1
			else:
				ans += 5
			visited.add((x, y, x, y + 1))
			visited.add((x, y + 1, x, y))
			y += 1
		elif s[i] == 'S':
			if (x, y, x, y - 1) in visited:
				ans += 1
			else:
				ans += 5
			visited.add((x, y, x, y - 1))
			visited.add((x, y - 1, x, y))
			y -= 1
		elif s[i] == 'E':
			if (x, y, x + 1, y) in visited:
				ans += 1
			else:
				ans += 5
			visited.add((x, y, x + 1, y))
			visited.add((x + 1, y, x, y))
			x += 1
		elif s[i] == 'W':
			if (x, y, x - 1, y) in visited:
				ans += 1
			else:
				ans += 5
			visited.add((x, y, x - 1, y))
			visited.add((x - 1, y, x, y))
			x -= 1
	print(ans)


import collections

def path_duration(path):
	duration = 0
	position = (0, 0)
	position_paths = collections.defaultdict(set)
	for direction in path:
		if direction == 'S':
			new_position = (position[0], position[1] - 1)
		elif direction == 'N':
			new_position = (position[0], position[1] + 1)
		elif direction == 'W':
			new_position = (position[0] - 1, position[1])
		elif direction == 'E':
			new_position = (position[0] + 1, position[1])
		if new_position in position_paths[position] or position in position_paths[new_position]:
			speed = 1
		else:
			speed = 5
		duration += speed
		position_paths[position].add(new_position)
		position = new_position
	return duration

def main():
	t = int(input())
	for _ in range(t):
		path = input()
		print(path_duration(path))
assert path_duration('NNN') == 15
assert path_duration('NS') == 6
assert path_duration('WWEN') == 16
assert path_duration('WWEE') == 12
assert path_duration('NWNWS') == 25
assert path_duration('ESWN') == 20
assert path_duration('WSESNN') == 26
main()


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
GO = {'N': (0, 1), 'S': (0, -1), 'W': (-1, 0), 'E': (1, 0)}
for _ in range(int(f_input())):
	answer = 0
	seen = set()
	(x, y) = (0, 0)
	for char in f_input().replace('\n', ''):
		x1 = x + GO[char][0]
		y1 = y + GO[char][1]
		if (x, y, x1, y1) in seen or (x1, y1, x, y) in seen:
			answer += 1
		else:
			answer += 5
			seen.add((x, y, x1, y1))
		(x, y) = (x1, y1)
	f_print(str(answer) + '\n')


for i in range(int(input())):
	way = input()
	ans = 0
	pt0 = (0, 0)
	tracks = set()
	for direct in way:
		if direct == 'N':
			pt1 = (pt0[0], pt0[1] + 1)
		elif direct == 'S':
			pt1 = (pt0[0], pt0[1] - 1)
		elif direct == 'E':
			pt1 = (pt0[0] + 1, pt0[1])
		elif direct == 'W':
			pt1 = (pt0[0] - 1, pt0[1])
		if (pt0, pt1) in tracks:
			ans += 1
		else:
			ans += 5
		tracks.add((pt0, pt1))
		tracks.add((pt1, pt0))
		pt0 = pt1
	print(int(ans))


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	s = input().strip('\n')
	d = {}
	t = 0
	pos = [0, 0]
	(dx, dy) = ({}, {})
	(dx['N'], dy['N']) = (0, 1)
	(dx['S'], dy['S']) = (0, -1)
	(dx['W'], dy['W']) = (-1, 0)
	(dx['E'], dy['E']) = (1, 0)
	for i in s:
		npos = [pos[0] + dx[i], pos[1] + dy[i]]
		if tuple(npos + pos) not in d:
			(d[tuple(pos + npos)], d[tuple(npos + pos)]) = (1, 1)
			t += 5
		else:
			t += 1
		pos = npos
	print(t)


anti = {'N': 'S', 'S': 'N', 'E': 'W', 'W': 'E'}
for _ in range(int(input())):
	s = input()
	x = 0
	y = 0
	g = set()
	c = 0
	prev = '0'
	for i in s:
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'W':
			x -= 1
		else:
			x += 1
		if i == 'N' and (x, y - 1, 'S') in g or (i == 'S' and (x, y + 1, 'N') in g) or (i == 'W' and (x + 1, y, 'E') in g) or (i == 'E' and (x - 1, y, 'W') in g) or ((x, y, i) in g):
			c += 1
		else:
			c += 5
			g.add((x, y, i))
	print(c)


for s in [*open(0)][1:]:
	rx = 0
	x = (0, 0)
	d = {}
	for c in s[:-1]:
		i = 'SNWE'.find(c)
		y = (x[0] + (1, -1, 0, 0)[i], x[1] + (0, 0, 1, -1)[i])
		p = (*sorted((x, y)),)
		x = y
		rx += d.get(p, 5)
		d[p] = 1
	print(rx)


for s in [*open(0)][1:]:
	r = x = 0
	d = {}
	for c in s[:-1]:
		y = 2 * x + (1, -1, 7 ** 6, -7 ** 6)['SNWE'.find(c)]
		x = y - x
		r += d.get(y, 5)
		d[y] = 1
	print(r)


import sys
import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	f = cc.defaultdict(int)
	ans = 0
	ss = set()
	f = cc.defaultdict(list)
	for i in s:
		(xx, yy) = (x, y)
		if i == 'S':
			y -= 1
		elif i == 'N':
			y += 1
		elif i == 'W':
			x -= 1
		else:
			x += 1
		if (xx, yy) in f[x, y]:
			ans += 1
		else:
			ans += 5
			f[x, y].append((xx, yy))
			f[xx, yy].append((x, y))
	print(ans)


t = int(input())
for _ in range(t):
	moves = input()
	paths = set()
	current_pos = (0, 0)
	meter = 0
	for move in moves:
		delta = (0, 0)
		if move == 'N':
			delta = (0, 1)
		if move == 'S':
			delta = (0, -1)
		if move == 'W':
			delta = (-1, 0)
		if move == 'E':
			delta = (1, 0)
		next_pos = (current_pos[0] + delta[0], current_pos[1] + delta[1])
		path = (current_pos, next_pos)
		reverse_path = (next_pos, current_pos)
		current_pos = next_pos
		if path in paths:
			meter += 1
		else:
			meter += 5
		paths.add(path)
		paths.add(reverse_path)
	print(meter)


n = int(input())
for i in range(n):
	s = input()
	visited = set()
	time = 0
	pos = [0, 0]
	for c in s:
		orig = pos.copy()
		path = orig
		revpath = orig
		if c == 'N':
			pos[0] += 1
		elif c == 'S':
			pos[0] -= 1
		elif c == 'E':
			pos[1] += 1
		elif c == 'W':
			pos[1] -= 1
		revpath = pos + orig
		path = orig + pos
		if tuple(path) in visited or tuple(revpath) in visited:
			time += 1
		else:
			time += 5
			visited.add(tuple(path))
			visited.add(tuple(revpath))
	print(time)


from sys import stdin, stdout
for _ in range(int(input())):
	path = input()
	pos = [0, 0]
	was = dict()
	was[0, 0] = set()
	time = 0
	for i in path:
		before = (pos[0], pos[1])
		if i == 'N':
			pos[1] += 1
		elif i == 'S':
			pos[1] -= 1
		elif i == 'E':
			pos[0] -= 1
		else:
			pos[0] += 1
		bf = (pos[0], pos[1])
		if bf in was[before]:
			time += 1
		else:
			time += 5
		if bf not in was:
			was[bf] = set()
		was[before].add(bf)
		was[bf].add(before)
	print(str(time))


import sys
try:
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')
except:
	pass
for testCases in range(int(input())):
	position = [0, 0]
	d = {}
	time = 0
	s = input()
	for i in s:
		dic = position[:]
		if i == 'N':
			position[0] += 1
		elif i == 'S':
			position[0] -= 1
		elif i == 'E':
			position[1] += 1
		else:
			position[1] -= 1
		dic0 = [min(dic[0], position[0]), max(dic[0], position[0])]
		dic1 = [min(dic[1], position[1]), max(dic[1], position[1])]
		dic = tuple(dic0 + dic1)
		if d.get(tuple(dic)):
			time += 1
		else:
			time += 5
			d[tuple(dic)] = 1
	print(time)


t = int(input())
opp = {'N': 'S', 'S': 'N', 'E': 'W', 'W': 'E'}
for _ in range(t):
	s = input()
	stack = []
	ans = 0
	(a, b) = (0, 0)
	path = set()
	for x in s:
		(newA, newB) = (a, b)
		if x == 'N':
			newB += 1
		if x == 'S':
			newB -= 1
		if x == 'W':
			newA -= 1
		if x == 'E':
			newA += 1
		if (a, b, newA, newB) in path or (newA, newB, a, b) in path:
			ans += 1
		else:
			ans += 5
		path.add((a, b, newA, newB))
		path.add((newA, newB, a, b))
		(a, b) = (newA, newB)
	print(ans)


for t in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	visited = {}
	ans = 0
	for i in s:
		(x1, y1) = (x, y)
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		else:
			x -= 1
		if visited.get(((x, y), (x1, y1)), False) == False and visited.get(((x1, y1), (x, y)), False) == False:
			ans += 5
			visited[(x, y), (x1, y1)] = True
		else:
			ans += 1
	print(ans)


for q in range(int(input())):
	s = input()
	visited = {}
	x = y = 0
	px = py = 0
	res = 0
	for i in s:
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'W':
			x -= 1
		else:
			x += 1
		if visited.get(((px, py), (x, y)), 0) == 1 or visited.get(((x, y), (px, py)), 0) == 1:
			res += 1
		else:
			res += 5
			visited[(px, py), (x, y)] = 1
			visited[(x, y), (px, py)] = 1
		px = x
		py = y
	print(res)


for _ in range(int(input())):
	s = input()
	ans = 0
	x = 0
	y = 0
	from_x = 0
	from_y = 0
	p = {}
	for c in s:
		if c == 'N':
			y += 1
		elif c == 'S':
			y -= 1
		elif c == 'E':
			x += 1
		else:
			x -= 1
		if (from_x, from_y, x, y) in p or (x, y, from_x, from_y) in p:
			ans += 1
		else:
			ans += 5
			p[from_x, from_y, x, y] = 0
		(from_x, from_y) = (x, y)
	print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	s = input()
	x = 0
	y = 0
	se = set()
	count = 0
	x1 = 0
	y1 = 0
	for i in s:
		if i == 'N':
			x1 = x + 1
		if i == 'S':
			x1 = x - 1
		if i == 'E':
			y1 = y + 1
		if i == 'W':
			y1 = y - 1
		if (x, y, x1, y1) in se:
			count += 1
		elif (x1, y1, x, y) in se:
			count += 1
		else:
			count += 5
			se.add((x, y, x1, y1))
		x = x1
		y = y1
	print(count)


for _ in range(int(input())):
	d = dict()
	x = y = 0
	ans = 0
	prevx = prevy = 0
	s = input()
	for i in range(len(s)):
		if s[i] == 'N':
			y += 1
		elif s[i] == 'S':
			y -= 1
		elif s[i] == 'E':
			x += 1
		else:
			x -= 1
		if (x, y, prevx, prevy) in d or (prevx, prevy, x, y) in d:
			ans += 1
		else:
			d[x, y, prevx, prevy] = 1
			d[prevx, prevy, x, y] = 1
			ans += 5
		prevx = x
		prevy = y
	print(ans)


def path(string):
	blanck = set()
	x = 0
	y = 0
	t = 0
	(px, py) = (0, 0)
	for i in string:
		if i == 'N':
			y += 1
			if (px, py, x, y) not in blanck:
				t += 5
			else:
				t += 1
		if i == 'S':
			y -= 1
			if (px, py, x, y) not in blanck:
				t += 5
			else:
				t += 1
		if i == 'E':
			x += 1
			if (px, py, x, y) not in blanck:
				t += 5
			else:
				t += 1
		if i == 'W':
			x -= 1
			if (px, py, x, y) not in blanck:
				t += 5
			else:
				t += 1
		blanck.add((px, py, x, y))
		blanck.add((x, y, px, py))
		(px, py) = (x, y)
	return t
n = int(input())
for i in range(n):
	print(path(input()))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
import copy
for _ in range(t):
	s = input()
	cur = [0, 0]
	ans = 0
	m = set()
	for i in s:
		ccur = copy.deepcopy(cur)
		if i == 'S':
			ccur[0] += 1
		elif i == 'N':
			ccur[0] -= 1
		elif i == 'W':
			ccur[1] += 1
		elif i == 'E':
			ccur[1] -= 1
		if tuple(ccur + cur) not in m and tuple(cur + ccur) not in m:
			m.add(tuple(ccur + cur))
			m.add(tuple(cur + ccur))
			ans += 5
		else:
			ans += 1
		cur = ccur
	print(ans)


T = int(input())
mov = [0] * T
for t in range(T):
	mov[t] = input()
pmy = {'N': 1, 'S': -1, 'E': 0, 'W': 0}
pmx = {'N': 0, 'S': 0, 'E': 1, 'W': -1}
di = {'N': 0, 'S': 0, 'E': 1, 'W': 1}
for t in range(T):
	x = 0
	y = 0
	poss = set([])
	time = 0
	for i in mov[t]:
		nx = x + pmx[i]
		ny = y + pmy[i]
		if (nx, ny, x, y) in poss:
			time += 1
		else:
			time += 5
		poss.add((nx, ny, x, y))
		poss.add((x, y, nx, ny))
		x = nx
		y = ny
	print(time)


for _ in range(int(input())):
	s = input()
	time = 0
	pos = set()
	a = (0, 0)
	for item in s:
		if item == 'N':
			b = (a[0], a[1] + 1)
		elif item == 'S':
			b = (a[0], a[1] - 1)
		elif item == 'E':
			b = (a[0] + 1, a[1])
		elif item == 'W':
			b = (a[0] - 1, a[1])
		if a + b in pos:
			time += 1
		else:
			time += 5
			pos.add(a + b)
			pos.add(b + a)
		a = b
	print(time)


from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	s = input()
	coord = set()
	x = 0
	y = 0
	lx = 0
	ly = 0
	sum = 0
	for c in s:
		lx = x
		ly = y
		if c == 'N':
			y += 1
		elif c == 'S':
			y -= 1
		elif c == 'E':
			x += 1
		else:
			x -= 1
		l = len(coord)
		coord.add(((lx, ly), (x, y)))
		coord.add(((x, y), (lx, ly)))
		if len(coord) > l:
			sum += 5
		else:
			sum += 1
	print(sum)


for _ in range(int(input())):
	(ans, px, py) = (0, 0, 0)
	s = set()
	for c in input():
		(nx, ny) = (px, py)
		if c == 'N':
			nx += 1
		if c == 'S':
			nx += -1
		if c == 'E':
			ny += 1
		if c == 'W':
			ny += -1
		ans += 1 if (px, py, nx, ny) in s else 5
		s.add((px, py, nx, ny))
		s.add((nx, ny, px, py))
		(px, py) = (nx, ny)
	print(ans)


t = int(input())
M = int(10 ** 5)
for _ in range(t):
	p = input()
	e = set()
	(x, y) = (0, 0)
	res = 0
	for d in p:
		(a, b) = (x, y)
		if d == 'N':
			b += 1
		elif d == 'S':
			b -= 1
		elif d == 'E':
			a += 1
		else:
			a -= 1
		(u, v) = (x * M + y, a * M + b)
		if (u, v) in e or (v, u) in e:
			res += 1
		else:
			e.add((u, v))
			res += 5
		(x, y) = (a, b)
	print(res)


def max(a, b, c, d):
	if a < c:
		return (c, d)
	elif a > c:
		return (a, b)
	elif b < d:
		return (c, d)
	else:
		return (a, b)

def min(a, b, c, d):
	if a > c:
		return (c, d)
	elif a > c:
		return (a, b)
	elif b > d:
		return (c, d)
	else:
		return (a, b)
for _ in range(int(input())):
	p = input()
	d = {}
	ans = 0
	x = y = 0
	for i in p:
		x1 = x
		y1 = y
		if i == 'S':
			y1 -= 1
		elif i == 'N':
			y1 += 1
		elif i == 'W':
			x1 -= 1
		else:
			x1 += 1
		if (min(x, y, x1, y1), max(x, y, x1, y1)) in d.keys():
			ans += 1
		else:
			ans += 5
		d[min(x, y, x1, y1), max(x, y, x1, y1)] = 1
		(x, y) = (x1, y1)
	print(ans)


t = int(input())
for o in range(t):
	s = input()
	c = 0
	x = 0
	y = 0
	a = set()
	for i in s:
		if i == 'E':
			b = ((x, y), (x + 1, y))
			d = ((x + 1, y), (x, y))
			x += 1
		elif i == 'W':
			b = ((x, y), (x - 1, y))
			d = ((x - 1, y), (x, y))
			x -= 1
		elif i == 'S':
			b = ((x, y), (x, y - 1))
			d = ((x, y - 1), (x, y))
			y -= 1
		else:
			b = ((x, y), (x, y + 1))
			d = ((x, y + 1), (x, y))
			y += 1
		if b in a or d in a:
			c += 1
		else:
			c += 5
		a.add(b)
	print(c)


shift = {'S': (0, -1), 'N': (0, 1), 'W': (-1, 0), 'E': (1, 0)}
for _ in range(int(input())):
	coords = {}
	(x, y) = (0, 0)
	time = 0
	for symbol in input():
		(dx, dy) = (x + shift[symbol][0], y + shift[symbol][1])
		time += min(coords.get((x, y, dx, dy), 5), coords.get((dx, dy, x, y), 5))
		coords[x, y, dx, dy] = 1
		(x, y) = (dx, dy)
	print(time)


t = int(input())
for a in range(t):
	path = input()
	current = [0, 0]
	answer = 0
	used = set()
	for step in path:
		if step == 'N':
			transition = (0, 1)
		if step == 'S':
			transition = (0, -1)
		if step == 'W':
			transition = (1, 0)
		if step == 'E':
			transition = (-1, 0)
		newPath = (current[0] + transition[0] / 2, current[1] + transition[1] / 2)
		if newPath in used:
			answer += 1
		else:
			answer += 5
			used.add(newPath)
		current[0] += transition[0]
		current[1] += transition[1]
	print(answer)


testCases = int(input())
res = []
while testCases:
	stringX = input()
	x = 0
	y = 0
	ans = 0
	stepsTracker = {}
	ans = 0
	for i in stringX:
		nx = x
		ny = y
		if i == 'E':
			x += 1
		elif i == 'W':
			x -= 1
		elif i == 'N':
			y += 1
		else:
			y -= 1
		try:
			if stepsTracker[x, y, nx, ny] == True:
				ans += 1
		except KeyError:
			ans += 5
		stepsTracker[nx, ny, x, y] = True
		stepsTracker[x, y, nx, ny] = True
	res.append(ans)
	testCases -= 1
for i in res:
	print(i)


import collections
import heapq
from bisect import bisect_right
import math

def create(a, b, c):
	if (a, b) in dic:
		if c not in dic[a, b]:
			dic[a, b].append(c)
	else:
		dic.update({(x, y): [c]})
t = int(input())
for w in range(t):
	s = input()
	x = 0
	y = 0
	count = 0
	dic = {}
	for j in s:
		if (x, y) in dic:
			if j in dic[x, y]:
				count += 1
				if j == 'N':
					y += 1
				elif j == 'S':
					y -= 1
				elif j == 'E':
					x += 1
				elif j == 'W':
					x -= 1
			else:
				count += 5
				create(x, y, j)
				if j == 'N':
					y += 1
					create(x, y, 'S')
				elif j == 'S':
					y -= 1
					create(x, y, 'N')
				elif j == 'E':
					x += 1
					create(x, y, 'W')
				elif j == 'W':
					x -= 1
					create(x, y, 'E')
		else:
			count += 5
			create(x, y, j)
			if j == 'N':
				y += 1
				create(x, y, 'S')
			elif j == 'S':
				y -= 1
				create(x, y, 'N')
			elif j == 'E':
				x += 1
				create(x, y, 'W')
			elif j == 'W':
				x -= 1
				create(x, y, 'E')
	print(count)


T = int(input())

def move(position, direction):
	if direction == 'N':
		(x, y) = position
		y = y + 1
		position = (x, y)
	elif direction == 'E':
		(x, y) = position
		x = x + 1
		position = (x, y)
	elif direction == 'S':
		(x, y) = position
		y = y - 1
		position = (x, y)
	elif direction == 'W':
		(x, y) = position
		x = x - 1
		position = (x, y)
	return position

def main():
	position = (0, 0)
	x = 1
	y = 0
	path = input()
	relations = {'N': 'S', 'S': 'N', 'E': 'W', 'W': 'E'}
	traversal = {position: [path[0]]}
	position = move(position, path[0])
	for i in range(1, len(path)):
		destination = move(position, path[i])
		value = traversal.get(position)
		d_value = traversal.get(destination)
		if value is None:
			if d_value is None:
				x = x + 1
			elif relations[path[i]] in d_value:
				y = y + 1
			else:
				x = x + 1
			traversal[position] = [path[i]]
			position = destination
		else:
			if path[i] in value:
				y = y + 1
			elif d_value is None:
				x = x + 1
			elif relations[path[i]] in d_value:
				y = y + 1
			else:
				x = x + 1
			value.append(path[i])
			traversal[position] = value
			position = destination
	print(x * 5 + y)
for _ in range(T):
	main()


from collections import defaultdict
for _ in range(int(input())):
	pos = [0, 0]
	e = defaultdict(int)
	w = defaultdict(int)
	n = defaultdict(int)
	s = defaultdict(int)
	sum = 0
	for i in input():
		pos1 = pos[:]
		if i == 'N':
			pos[1] += 1
		elif i == 'S':
			pos[1] -= 1
		elif i == 'E':
			pos[0] += 1
		else:
			pos[0] -= 1
		x = (pos[0] + pos1[0]) / 2
		y = (pos[1] + pos1[1]) / 2
		if x >= 0 and y >= 0:
			if (x, y) in e:
				sum += 1
			else:
				sum += 5
				e[x, y] = 0
		if x >= 0 and y < 0:
			if (x, y) in w:
				sum += 1
			else:
				sum += 5
				w[x, y] = 0
		if x < 0 and y < 0:
			if (x, y) in n:
				sum += 1
			else:
				sum += 5
				n[x, y] = 0
		if x < 0 and y >= 0:
			if (x, y) in s:
				sum += 1
			else:
				sum += 5
				s[x, y] = 0
	print(sum)


for _ in range(int(input())):
	s = str(input())
	d = {}
	x = 0
	y = 0
	c = 0
	for i in s:
		t4 = x
		t5 = y
		if i == 'E':
			x -= 1
		elif i == 'W':
			x += 1
		elif i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		t3 = (t4, t5, x, y)
		t2 = (x, y, t4, t5)
		if t3 in d.keys() or t2 in d.keys():
			c += 1
		else:
			c += 5
			d[t2] = 0
			d[t3] = 0
	print(c)


cord = {'N': (0, 1), 'S': (0, -1), 'W': (-1, 0), 'E': (1, 0)}
for _ in range(int(input())):
	s = input()
	x_y = (0, 0)
	cost = 0
	dictxy = {}
	for c in s:
		x_ = x_y[0] + cord[c][0]
		y_ = x_y[1] + cord[c][1]
		cost += min(dictxy.get((x_y[0], x_y[1], x_, y_), 5), dictxy.get((x_, y_, x_y[0], x_y[1]), 5))
		dictxy[x_y[0], x_y[1], x_, y_] = 1
		x_y = (x_, y_)
	print(cost)


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

def solve(char):
	(x, y, total) = (0, 0, 0)
	path_bothdir = {}
	for i in char:
		cx = x + dic[i][0]
		cy = y + dic[i][1]
		total += min(path_bothdir.get((cx, cy, x, y), 5), path_bothdir.get((x, y, cx, cy), 5))
		path_bothdir[cx, cy, x, y] = 1
		x = cx
		y = cy
	return total
t = int(input())
out = []
for j in range(t):
	char = input()
	out.append(solve(char))
for m in out:
	print(m)


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
for _ in range(INI()):
	S = input()
	ANS = set()
	(x, y) = (0, 0)
	ans = 0
	for _ in S:
		if _ == 'N':
			if ((x, y), (x, y + 1)) in ANS:
				ans += 1
			else:
				ans += 5
				ANS.add(((x, y), (x, y + 1)))
				ANS.add(((x, y + 1), (x, y)))
			y += 1
		if _ == 'S':
			if ((x, y), (x, y - 1)) in ANS:
				ans += 1
			else:
				ans += 5
				ANS.add(((x, y), (x, y - 1)))
				ANS.add(((x, y - 1), (x, y)))
			y -= 1
		if _ == 'E':
			if ((x, y), (x + 1, y)) in ANS:
				ans += 1
			else:
				ans += 5
				ANS.add(((x, y), (x + 1, y)))
				ANS.add(((x + 1, y), (x, y)))
			x += 1
		if _ == 'W':
			if ((x, y), (x - 1, y)) in ANS:
				ans += 1
			else:
				ans += 5
				ANS.add(((x, y), (x - 1, y)))
				ANS.add(((x - 1, y), (x, y)))
			x -= 1
	OPS(ans)


from collections import defaultdict as defd

def printv(a, sep=' '):
	print(sep.join(map(str, a)))

def solve(s):
	(x, y) = (0, 0)
	d = defd(int)
	k = 0
	for i in s:
		(x1, y1) = (x, y)
		if i == 'S':
			y1 -= 1
		elif i == 'N':
			y1 += 1
		elif i == 'W':
			x1 -= 1
		else:
			x1 += 1
		if d[x, y, x1, y1] == 1:
			k += 1
		else:
			d[x, y, x1, y1] = 1
			d[x1, y1, x, y] = 1
			k += 5
		(x, y) = (x1, y1)
	return k

def main():
	t = int(input())
	ans = [0] * t
	for i in range(t):
		s = input()
		ans[i] = solve(s)
	printv(ans, '\n')
main()


t = int(input())
for it in range(t):
	alphas = input()
	(x, y) = (0, 0)
	total_time = 0
	path_d = dict()
	for a in alphas:
		if a == 'S':
			forward = path_d.get((x, y, x, y - 1), 5)
			back = path_d.get((x, y - 1, x, y), 5)
			total_time += min(forward, back)
			path_d[x, y - 1, x, y] = 1
			path_d[x, y, x, y - 1] = 1
			(x, y) = (x, y - 1)
		if a == 'N':
			forward = path_d.get((x, y, x, y + 1), 5)
			back = path_d.get((x, y + 1, x, y), 5)
			total_time += min(forward, back)
			path_d[x, y + 1, x, y] = 1
			path_d[x, y, x, y + 1] = 1
			(x, y) = (x, y + 1)
		if a == 'W':
			forward = path_d.get((x, y, x - 1, y), 5)
			back = path_d.get((x, y, x - 1, y), 5)
			total_time += min(forward, back)
			path_d[x - 1, y, x, y] = 1
			path_d[x, y, x - 1, y] = 1
			(x, y) = (x - 1, y)
		if a == 'E':
			forward = path_d.get((x, y, x + 1, y), 5)
			back = path_d.get((x + 1, y, x, y), 5)
			total_time += min(forward, back)
			path_d[x + 1, y, x, y] = 1
			path_d[x, y, x + 1, y] = 1
			(x, y) = (x + 1, y)
	print(total_time)


t = int(input())
for _ in range(t):
	p = input()
	pos = (0, 0)
	visited = set()
	t = 0
	for d in p:
		if d == 'N':
			new_pos = (pos[0], pos[1] - 1)
		elif d == 'S':
			new_pos = (pos[0], pos[1] + 1)
		elif d == 'W':
			new_pos = (pos[0] - 1, pos[1])
		elif d == 'E':
			new_pos = (pos[0] + 1, pos[1])
		if (pos, new_pos) in visited or (new_pos, pos) in visited:
			t += 1
		else:
			visited.add((pos, new_pos))
			t += 5
		pos = new_pos
	print(t)


t = int(input())
for _ in range(t):
	(x, y) = (0, 0)
	time = 0
	path = input()
	covered = dict()
	covered[0, 0] = [False] * 4
	for p in path:
		if p == 'N':
			newX = x
			newY = y + 1
		elif p == 'S':
			newX = x
			newY = y - 1
		elif p == 'E':
			newX = x + 1
			newY = y
		else:
			newX = x - 1
			newY = y
		if (newX, newY) not in covered:
			covered[newX, newY] = [False] * 4
		seen = False
		if p == 'N':
			if covered[newX, newY][1]:
				seen = True
			else:
				covered[newX, newY][1] = True
				covered[x, y][0] = True
		if p == 'S':
			if covered[newX, newY][0]:
				seen = True
			else:
				covered[newX, newY][0] = True
				covered[x, y][1] = True
		if p == 'E':
			if covered[newX, newY][3]:
				seen = True
			else:
				covered[newX, newY][3] = True
				covered[x, y][2] = True
		if p == 'W':
			if covered[newX, newY][2]:
				seen = True
			else:
				covered[newX, newY][2] = True
				covered[x, y][3] = True
		if seen:
			time += 1
		else:
			time += 5
		(x, y) = (newX, newY)
	print(time)


for _ in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	myset = set()
	ans = 0
	for i in s:
		sub = ((x, y),)
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x -= 1
		else:
			x += 1
		sub += ((x, y),)
		if sub in myset or sub[::-1] in myset:
			ans += 1
		else:
			ans += 5
			myset.add(sub)
	print(ans)


import sys
sys.setrecursionlimit(10 ** 6)

def ii():
	return int(sys.stdin.readline())

def si():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(ii()):
		s = si()
		xx = set()
		yy = set()
		ans = 0
		(x, y) = (0, 0)
		for c in s:
			if c == 'N':
				if (x, y) in yy:
					ans += 1
				else:
					ans += 5
				yy.add((x, y))
				y += 1
			if c == 'S':
				y -= 1
				if (x, y) in yy:
					ans += 1
				else:
					ans += 5
				yy.add((x, y))
			if c == 'E':
				if (x, y) in xx:
					ans += 1
				else:
					ans += 5
				xx.add((x, y))
				x += 1
			if c == 'W':
				x -= 1
				if (x, y) in xx:
					ans += 1
				else:
					ans += 5
				xx.add((x, y))
		print(ans)
main()


for _ in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	d = {'N': (1, 0), 'S': (-1, 0), 'W': (0, 1), 'E': (0, -1)}
	rs = 0
	vst = set()
	for i in s:
		u = x + d[i][0]
		v = y + d[i][1]
		if (x, y, u, v) in vst:
			rs += 1
		else:
			rs += 5
			vst.add((x, y, u, v))
			vst.add((u, v, x, y))
		(x, y) = (u, v)
	print(rs)


import sys
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
dir = {'N': (-1, 0), 'S': (1, 0), 'E': (0, -1), 'W': (0, 1)}

def solve():
	s = ns()
	seen = set()
	(x, y) = (0, 0)
	cnt = 0
	for s in s:
		(old_x, old_y) = (x, y)
		x += dir[s][0]
		y += dir[s][1]
		if (old_x, old_y, x, y) in seen:
			cnt += 1
		else:
			cnt += 5
			seen.add((old_x, old_y, x, y))
			seen.add((x, y, old_x, old_y))
	print(cnt)
t = ni()
for _ in range(t):
	solve()


t = int(input())
for test in range(t):
	ans = 0
	pos = (0, 0)
	d = {(0, 0): set()}
	s = input()
	for i in s:
		fast = False
		if i == 'S':
			new = (pos[0] - 1, pos[1])
		elif i == 'N':
			new = (pos[0] + 1, pos[1])
		elif i == 'W':
			new = (pos[0], pos[1] - 1)
		elif i == 'E':
			new = (pos[0], pos[1] + 1)
		if d.get(pos) != None:
			if new in d[pos]:
				fast = True
			else:
				d[pos].add(new)
				if d.get(new) != None:
					d[new].add(pos)
				else:
					d[new] = {pos}
		else:
			d[pos] = {new}
			d[new] = {pos}
		pos = new
		if fast:
			ans += 1
		else:
			ans += 5
	print(ans)


from math import *
from collections import *
from operator import itemgetter
import bisect
i = lambda : input()
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
t = ii()
for _ in range(t):
	s = input()
	d = defaultdict(lambda : [0, 0, 0, 0])
	dm = {'N': 0, 'S': 1, 'E': 2, 'W': 3}
	(x, y) = (0, 0)
	cost = 0
	for i in s:
		p = (x, y)
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		elif i == 'W':
			x -= 1
		b = (x, y)
		ans1 = d[b]
		ans2 = d[p]
		if i == 'N':
			if d[p][0] == 0:
				cost += 5
			else:
				cost += 1
			d[p][0] = 1
			d[b][1] = 1
		elif i == 'S':
			if d[p][1] == 0:
				cost += 5
			else:
				cost += 1
			d[p][1] = 1
			d[b][0] = 1
		elif i == 'E':
			if d[p][2] == 0:
				cost += 5
			else:
				cost += 1
			d[p][2] = 1
			d[b][3] = 1
		elif i == 'W':
			if d[p][3] == 0:
				cost += 5
			else:
				cost += 1
			d[p][3] = 1
			d[b][2] = 1
	print(cost)


num_lines = int(input())
for _ in range(num_lines):
	d = input()
	c = 0
	points = set()
	start_point = (0, 0)
	for s in d:
		if s == 'N':
			end_point = (start_point[0] + 1, start_point[1])
		if s == 'S':
			end_point = (start_point[0] - 1, start_point[1])
		if s == 'W':
			end_point = (start_point[0], start_point[1] + 1)
		if s == 'E':
			end_point = (start_point[0], start_point[1] - 1)
		t = (start_point, end_point)
		if t in points or (t[1], t[0]) in points:
			c += 1
		else:
			c += 5
		points.add(t)
		start_point = end_point
	print(c)


import sys

def main():
	input_list = get_input()
	for line in range(len(input_list)):
		if line >= 1:
			print(path_time(input_list[line]))

def get_input():
	input_list = []
	for line in sys.stdin:
		input_list.append(line.rstrip('\n'))
	return input_list

def path_time(input_string):
	visited_set = set()
	(x_pos, y_pos, last_x, last_y) = (0, 0, 0, 0)
	time = 0
	for direction in input_string:
		last_x = x_pos
		last_y = y_pos
		if direction == 'N':
			y_pos += 1
		elif direction == 'S':
			y_pos -= 1
		elif direction == 'E':
			x_pos += 1
		elif direction == 'W':
			x_pos -= 1
		if (last_x, last_y, x_pos, y_pos) in visited_set:
			time += 1
		else:
			time += 5
		visited_set.add((last_x, last_y, x_pos, y_pos))
		visited_set.add((x_pos, y_pos, last_x, last_y))
	return time
main()


for _ in range(int(input())):
	(x, y) = (0, 0)
	t = 0
	myset = set()
	directions = input()
	for d in directions:
		(x2, y2) = (x, y)
		if d == 'N':
			y2 += 1
		elif d == 'S':
			y2 -= 1
		elif d == 'E':
			x2 += 1
		elif d == 'W':
			x2 -= 1
		if (x, y, x2, y2) in myset or (x2, y2, x, y) in myset:
			t += 1
		else:
			t += 5
		myset.add((x, y, x2, y2))
		(x, y) = (x2, y2)
	print(t)


import math
import sys

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		self.adj_list[u].append(v)
		if self.is_directed == False:
			self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print(node, '->', self.adj_list[node])

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)
				parents.append(i)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 1)
		parents = [v]
		self.dfsUTIL(v, visited, parents)
		return len(parents)

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(x, a, b, c):
	return a * x * x + b * x + c

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())
t = int(input())
for _ in range(t):
	s = input()
	a = set()
	x = y = 0
	time = 0
	for i in s:
		(x1, y1) = (x, y)
		if i == 'N':
			x += 1
		elif i == 'S':
			x -= 1
		elif i == 'E':
			y += 1
		else:
			y -= 1
		if (x, y, x1, y1) in a or (x1, y1, x, y) in a:
			time += 1
		else:
			a.add((x, y, x1, y1))
			time += 5
	print(time)


for _ in range(int(input())):
	path = input()
	d = {}
	ans = 0
	(x, y) = (0, 0)
	for ch in path:
		(nx, ny) = (x, y)
		if ch == 'N':
			ny += 1
		elif ch == 'S':
			ny -= 1
		elif ch == 'E':
			nx += 1
		else:
			nx -= 1
		if (x, y, nx, ny) in d or (nx, ny, x, y) in d:
			ans += 1
		else:
			ans += 5
			d[x, y, nx, ny] = 1
			d[nx, ny, x, y] = 1
		(x, y) = (nx, ny)
	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(ans)


for _ in int(input()) * [0]:
	D = {}
	cost = 0
	s = input()
	(x, y, u, v) = (0, 0, 0, 0)
	for i in s:
		(u, v) = (x, y)
		if i == 'N':
			v += 1
			if (x, y, u, v) not in D.keys() and (u, v, x, y) not in D.keys():
				D[x, y, u, v] = 1
				cost += 5
			else:
				cost += 1
		elif i == 'S':
			v -= 1
			if (x, y, u, v) not in D.keys() and (u, v, x, y) not in D.keys():
				D[x, y, u, v] = 1
				cost += 5
			else:
				cost += 1
		elif i == 'W':
			u += 1
			if (x, y, u, v) not in D.keys() and (u, v, x, y) not in D.keys():
				D[x, y, u, v] = 1
				cost += 5
			else:
				cost += 1
		elif i == 'E':
			u -= 1
			if (x, y, u, v) not in D.keys() and (u, v, x, y) not in D.keys():
				D[x, y, u, v] = 1
				cost += 5
			else:
				cost += 1
		(x, y) = (u, v)
	print(cost)


def main():
	t = int(input())
	opp = {'N': (-1, 0), 'S': (1, 0), 'W': (0, -1), 'E': (0, 1)}
	x = 0
	y = 0
	for __ in range(t):
		s = input()
		n = len(s)
		seg = set()
		cost = 0
		for i in range(n):
			if (x, y, x + opp[s[i]][0], y + opp[s[i]][1]) in seg or (x + opp[s[i]][0], y + opp[s[i]][1], x, y) in seg:
				cost += 1
			else:
				seg.add((x, y, x + opp[s[i]][0], y + opp[s[i]][1]))
				cost += 5
			x += opp[s[i]][0]
			y += opp[s[i]][1]
		print(cost)
main()


n = int(input())
for i in range(n):
	s = input()
	m = {}
	cur = [0, 0]
	ans = 0
	for c in s:
		if c == 'N':
			if (cur[0], cur[1]) in m and 'N' in m[cur[0], cur[1]]:
				ans += 1
			elif (cur[0] + 1, cur[1]) in m and 'S' in m[cur[0] + 1, cur[1]]:
				ans += 1
			else:
				ans += 5
			if (cur[0], cur[1]) in m:
				m[cur[0], cur[1]].add('N')
			else:
				m[cur[0], cur[1]] = {'N'}
			cur[0] = cur[0] + 1
		elif c == 'S':
			if (cur[0], cur[1]) in m and 'S' in m[cur[0], cur[1]]:
				ans += 1
			elif (cur[0] - 1, cur[1]) in m and 'N' in m[cur[0] - 1, cur[1]]:
				ans += 1
			else:
				ans += 5
			if (cur[0], cur[1]) in m:
				m[cur[0], cur[1]].add('S')
			else:
				m[cur[0], cur[1]] = {'S'}
			cur[0] = cur[0] - 1
		elif c == 'E':
			if (cur[0], cur[1]) in m and 'E' in m[cur[0], cur[1]]:
				ans += 1
			elif (cur[0], cur[1] + 1) in m and 'W' in m[cur[0], cur[1] + 1]:
				ans += 1
			else:
				ans += 5
			if (cur[0], cur[1]) in m:
				m[cur[0], cur[1]].add('E')
			else:
				m[cur[0], cur[1]] = {'E'}
			cur[1] = cur[1] + 1
		elif c == 'W':
			if (cur[0], cur[1]) in m and 'W' in m[cur[0], cur[1]]:
				ans += 1
			elif (cur[0], cur[1] - 1) in m and 'E' in m[cur[0], cur[1] - 1]:
				ans += 1
			else:
				ans += 5
			if (cur[0], cur[1]) in m:
				m[cur[0], cur[1]].add('W')
			else:
				m[cur[0], cur[1]] = {'W'}
			cur[1] = cur[1] - 1
	print(ans)


t = int(input())
for i in range(t):
	st = input()
	x = 0
	y = 0
	coords = set()
	time = 0
	for j in st:
		n1 = y
		n2 = x
		if j == 'N':
			n1 = y + 1
		elif j == 'S':
			n1 = y - 1
		elif j == 'W':
			n2 -= 1
		else:
			n2 += 1
		if tuple((x, y, n2, n1)) in coords:
			time += 1
		elif tuple((n2, n1, x, y)) in coords:
			time += 1
		else:
			coords.add(tuple((x, y, n2, n1)))
			time += 5
		x = n2
		y = n1
	print(time)


t = int(input())
for _ in range(t):
	s = input()
	here = [0, 0]
	nex = [0, 0]
	used = set()
	times = 0
	for i in range(len(s)):
		if s[i] == 'N':
			nex = [here[0], here[1] + 1]
		elif s[i] == 'S':
			nex = [here[0], here[1] - 1]
		elif s[i] == 'W':
			nex = [here[0] - 1, here[1]]
		elif s[i] == 'E':
			nex = [here[0] + 1, here[1]]
		if (here[0], here[1], nex[0], nex[1]) not in used:
			used.add((here[0], here[1], nex[0], nex[1]))
			used.add((nex[0], nex[1], here[0], here[1]))
			times += 5
		else:
			times += 1
		here = nex
	print(times)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))
mo = 1000000007
for _ in range(inn()):
	d = defaultdict(int)
	s = input()
	x = 0
	y = 0
	(lx, ly) = (0, 0)
	ans = 0
	for i in s:
		(lx, ly) = (x, y)
		if i == 'N':
			y += 1
		if i == 'S':
			y -= 1
		if i == 'E':
			x += 1
		if i == 'W':
			x -= 1
		if (x, y, lx, ly) not in d:
			d[x, y, lx, ly] += 1
			d[lx, ly, x, y] += 1
			ans += 5
		else:
			ans += 1
	print(ans)


for _ in ' ' * int(input()):
	d = {}
	(x, y) = (0, 0)
	ans = 0
	for i in input():
		(x1, y1) = (x, y)
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		else:
			x -= 1
		if (x, y, x1, y1) in d or (x1, y1, x, y) in d:
			ans += 1
		else:
			ans += 5
			d[x1, y1, x, y] = 1
	print(ans)


def skier(s):
	ans = 0
	paths = set()
	x = y = 0
	for d in s:
		source = '%s-%s' % (x, y)
		if d == 'N':
			y += 1
		elif d == 'S':
			y -= 1
		elif d == 'W':
			x -= 1
		elif d == 'E':
			x += 1
		destination = '%s-%s' % (x, y)
		path1 = '%s-%s' % (source, destination)
		path2 = '%s-%s' % (destination, source)
		if path1 in paths or path2 in paths:
			ans += 1
		else:
			paths.add(path1)
			paths.add(path2)
			ans += 5
	return ans
t = int(input())
for _ in range(t):
	s = str(input())
	ans = skier(s)
	print(ans)


import sys
import math
from collections import defaultdict
mod = 1000000007
T = 1
T = int(sys.stdin.readline())
for _ in range(T):
	s = input()
	d = {}
	ans = 0
	(x, y) = (0, 0)
	for i in s:
		(nx, ny) = (x, y)
		if i == 'N':
			ny += 1
		elif i == 'S':
			ny -= 1
		elif i == 'W':
			nx -= 1
		else:
			nx += 1
		if (x, y) in d and (nx, ny) in d[x, y]:
			ans += 1
		else:
			ans += 5
			if (nx, ny) not in d:
				d[nx, ny] = [(x, y)]
			else:
				d[nx, ny].append((x, y))
			if (x, y) not in d:
				d[x, y] = [(nx, ny)]
			else:
				d[x, y].append((nx, ny))
		(x, y) = (nx, ny)
	print(ans)


for _ in range(int(input())):
	s = input()
	st = set()
	cur = [0, 1]
	ans = 0
	for c in s:
		prev = list(cur)
		if c == 'N':
			cur[0] += 1
		if c == 'S':
			cur[0] -= 1
		if c == 'W':
			cur[1] += 1
		if c == 'E':
			cur[1] -= 1
		path = tuple(sorted((tuple(cur), tuple(prev))))
		ans += 1 if path in st else 5
		st.add(path)
	print(ans)


from collections import defaultdict
a = int(input())
for i in range(a):
	s = input()
	al = defaultdict(int)
	ore = (str(0), str(0))
	x = 0
	y = 0
	total = 0
	for i in range(len(s)):
		if s[i] == 'N':
			x += 1
		if s[i] == 'E':
			y += 1
		if s[i] == 'W':
			y -= 1
		if s[i] == 'S':
			x -= 1
		dest = (str(y), str(x))
		p1 = (ore, dest)
		p2 = (dest, ore)
		if al[p1] == 1 or al[p2] == 1:
			total += 1
		else:
			al[p1] = 1
			al[p2] = 1
			total += 5
		ore = dest
	print(total)


for s in [*open(0)][1:]:
	r = 0
	x = (0, 0)
	d = {}
	for c in s[:-1]:
		i = 'SNWE'.find(c)
		y = (x[0] + (1, -1, 0, 0)[i], x[1] + (0, 0, 1, -1)[i])
		r += d.get((x, y), 5)
		d[x, y] = d[y, x] = 1
		x = y
	print(r)


from collections import Counter
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	x = 0
	y = 0
	A = []
	for i in s:
		if i == 'N':
			A.append([x, y, x, y + 1])
			y += 1
		if i == 'S':
			A.append([x, y - 1, x, y])
			y -= 1
		if i == 'W':
			A.append([x - 1, y, x, y])
			x -= 1
		if i == 'E':
			A.append([x, y, x + 1, y])
			x += 1
	output = Counter([tuple(i) for i in A])
	st = len(output) * 5
	st += n - len(output)
	print(st)


for i in range(int(input())):
	a = input()
	c = set()
	d = (0, 0)
	(f, e) = (0, (0, 0))
	for i in a:
		if i == 'S':
			e = (d[0], d[1] - 1)
		elif i == 'N':
			e = (d[0], d[1] + 1)
		elif i == 'E':
			e = (d[0] + 1, d[1])
		elif i == 'W':
			e = (d[0] - 1, d[1])
		if (d, e) in c or (e, d) in c:
			f += 1
		else:
			c.add((d, e))
			f += 5
		d = e
	print(f)


for t in range(int(input())):
	a = list(input())
	b = {}
	c = x = y = 0
	for i in range(len(a)):
		if a[i] == 'S':
			x1 = x
			y1 = y - 1
		elif a[i] == 'N':
			x1 = x
			y1 = y + 1
		elif a[i] == 'W':
			x1 = x - 1
			y1 = y
		else:
			x1 = x + 1
			y1 = y
		s1 = str(x) + ',' + str(y) + ',' + str(x1) + ',' + str(y1)
		s2 = str(x1) + ',' + str(y1) + ',' + str(x) + ',' + str(y)
		if s1 in b or s2 in b:
			c += 1
		else:
			b[s1] = 1
			c += 5
		x = x1
		y = y1
	print(c)


t = int(input())
for i in range(t):
	s = input()
	x = 0
	y = 0
	time = 0
	dick = dict(())
	dick[0, 0] = True
	for j in s:
		x1 = x
		y1 = y
		if j == 'N':
			y += 1
		if j == 'S':
			y -= 1
		if j == 'W':
			x -= 1
		if j == 'E':
			x += 1
		if not dick.get((x, y, x1, y1), False):
			time += 5
			dick[x, y, x1, y1] = True
			dick[x1, y1, x, y] = True
		else:
			time += 1
	print(time)


def skier(s):
	store = set()
	(x, y) = (0, 0)
	for char in s:
		if char == 'N':
			store.add('{0} {1} - {2} {3}'.format(x, y, x, y + 1))
			y += 1
		elif char == 'S':
			store.add('{0} {1} - {2} {3}'.format(x, y - 1, x, y))
			y -= 1
		elif char == 'E':
			store.add('{0} {1} - {2} {3}'.format(x, y, x - 1, y))
			x -= 1
		elif char == 'W':
			store.add('{0} {1} - {2} {3}'.format(x + 1, y, x, y))
			x += 1
	s_len = len(store)
	result = s_len * 5 + (len(s) - s_len)
	return result
n = int(input())
for i in range(n):
	line1 = input().strip()
	print(skier(line1))


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(int(input())):
	s = input()
	d = set()
	x = 0
	y = 0
	ans = 0
	for i in range(len(s)):
		temp = (x, y)
		if s[i] == 'N':
			x += 1
		elif s[i] == 'S':
			x -= 1
		elif s[i] == 'W':
			y -= 1
		else:
			y += 1
		if (x, y) + temp in d or temp + (x, y) in d:
			ans += 1
		else:
			d.add((x, y) + temp)
			ans += 5
	print(ans)


t = int(input())
for i in range(t):
	a = input()
	b = set([])
	i = 0
	j = 0
	s = 0
	for K in range(len(a)):
		(c, d) = (i, j)
		if a[K] == 'N':
			j += 1
		elif a[K] == 'S':
			j -= 1
		elif a[K] == 'E':
			i += 1
		elif a[K] == 'W':
			i -= 1
		if ((i + c) / 2, (j + d) / 2) in b:
			s = s + 1
		else:
			s = s + 5
			b.add(((i + c) / 2, (j + d) / 2))
	print(s)


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


from sys import stdin, stdout
import math
import bisect
from collections import defaultdict
import datetime
import random
q = int(stdin.readline().strip())
while q:
	a = stdin.readline().strip()
	x = 0
	y = 0
	pending = set()
	for each in a:
		tmpx = x
		tmpy = y
		if each == 'N':
			y += 1
		elif each == 'S':
			y -= 1
		elif each == 'W':
			x -= 1
		else:
			x += 1
		pending.add(((x, y), (tmpx, tmpy)))
		pending.add(((tmpx, tmpy), (x, y)))
	ans = len(pending) // 2 * 5 + (len(a) - len(pending) // 2)
	stdout.writelines(str(ans) + '\n')
	q -= 1


n = int(input())
output = []
for _ in range(n):
	d = input()
	l = len(d)
	x = 0
	y = 0
	vis = {}
	time = 0
	for i in range(l):
		tmp = d[i]
		m1 = x
		m2 = y
		if tmp == 'N':
			y += 1
		elif tmp == 'S':
			y -= 1
		elif tmp == 'E':
			x -= 1
		elif tmp == 'W':
			x += 1
		if str(x) + ' ' + str(y) + ' ' + str(m1) + ' ' + str(m2) not in vis and str(m1) + ' ' + str(m2) + ' ' + str(x) + ' ' + str(y) not in vis:
			time += 5
			vis[str(x) + ' ' + str(y) + ' ' + str(m1) + ' ' + str(m2)] = 1
		else:
			time += 1
	output.append(time)
for o in output:
	print(o)


numTest = int(input())
for _ in range(numTest):
	inputLine = input()
	totoalTime = 0
	preX = 0
	preY = 0
	nowX = 0
	nowY = 0
	visitRoad = set()
	for eachWay in inputLine:
		preX = nowX
		preY = nowY
		if eachWay == 'S':
			nowY = nowY - 1
		elif eachWay == 'N':
			nowY = nowY + 1
		elif eachWay == 'W':
			nowX = nowX - 1
		elif eachWay == 'E':
			nowX = nowX + 1
		addTime = 1 if (preX, preY, nowX, nowY) in visitRoad or (nowX, nowY, preX, preY) in visitRoad else 5
		totoalTime = totoalTime + addTime
		if (preX, preY, nowX, nowY) not in visitRoad:
			visitRoad.add((preX, preY, nowX, nowY))
	print(totoalTime)


t = int(input())
for j in range(t):
	a = input()
	q = dict()
	c = 0
	(x, y) = (0, 0)
	for i in range(len(a)):
		w = str(x) + ' ' + str(y)
		if a[i] == 'N':
			y = y + 1
		if a[i] == 'S':
			y = y - 1
		if a[i] == 'E':
			x = x + 1
		if a[i] == 'W':
			x = x - 1
		if q.get(w + ' ' + str(x) + ' ' + str(y)):
			c = c + 1
		else:
			c = c + 5
		q[w + ' ' + str(x) + ' ' + str(y)] = 1
		q[str(x) + ' ' + str(y) + ' ' + w] = 1
	print(c)


for _ in range(int(input())):
	(initialx, initialy, x, y) = (0, 0, 0, 0)
	sett = set()
	string = str(input())
	time = 0
	for i in string:
		if i == 'N':
			y += 1
		if i == 'S':
			y -= 1
		if i == 'E':
			x += 1
		if i == 'W':
			x -= 1
		if (initialx, initialy, x, y) in sett:
			time += 1
		else:
			time += 5
			sett.add((initialx, initialy, x, y))
			sett.add((x, y, initialx, initialy))
		initialy = y
		initialx = x
	print(time)


def solve(str):
	x = 0
	y = 0
	prevX = 0
	prevY = 0
	map = set([(x, y, prevX, prevY)])
	time = 0
	for c in str:
		prevX = x
		prevY = y
		if c == 'N':
			y = y + 1
		elif c == 'S':
			y = y - 1
		elif c == 'W':
			x = x - 1
		elif c == 'E':
			x = x + 1
		if (x, y, prevX, prevY) in map or (prevX, prevY, x, y) in map:
			time = time + 1
		else:
			time = time + 5
		map.add((x, y, prevX, prevY))
	return time
t = int(input())
for i in range(0, t):
	s = input()
	print(solve(s))


for _ in range(int(input())):
	visited = {}
	s = input()
	(p1, p2, count, n) = (0, 0, 0, len(s))
	for i in range(n):
		(prev1, prev2) = (p1, p2)
		if s[i] == 'N':
			p1 += 1
		if s[i] == 'S':
			p1 -= 1
		if s[i] == 'E':
			p2 += 1
		if s[i] == 'W':
			p2 -= 1
		if tuple([prev1, prev2, p1, p2]) not in visited:
			visited[tuple([prev1, prev2, p1, p2])] = 0
			visited[tuple([p1, p2, prev1, prev2])] = 0
			count += 5
		else:
			count += 1
	print(count)


import sys
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def slv(S):
	v = set()
	c = (0, 0)
	ans = 0
	for s in S:
		if s == 'N':
			n = (c[0], c[1] + 1)
		elif s == 'S':
			n = (c[0], c[1] - 1)
		elif s == 'E':
			n = (c[0] + 1, c[1])
		elif s == 'W':
			n = (c[0] - 1, c[1])
		else:
			assert False
		if (c, n) in v or (n, c) in v:
			ans += 1
		else:
			v.add((c, n))
			ans += 5
		c = n
	return ans

def main():
	T = read_int()
	for _ in range(T):
		S = read_str()
		print(slv(S))
main()


t = int(input())
for _ in range(t):
	directions = input()
	(x, y) = (0, 0)
	m = {}
	m[x, y] = 1
	ans = 0
	for d in directions:
		(nx, ny) = (x, y)
		if d == 'N':
			ny += 1
		elif d == 'S':
			ny -= 1
		elif d == 'E':
			nx += 1
		elif d == 'W':
			nx -= 1
		if ((x, y), (nx, ny)) in m:
			ans += 1
		else:
			ans += 5
			m[(x, y), (nx, ny)] = 1
			m[(nx, ny), (x, y)] = 1
		(x, y) = (nx, ny)
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	cost = 0
	path = {}
	x = 0
	y = 0
	for i in range(len(s)):
		px = x
		py = y
		if s[i] == 'N':
			x += 1
		if s[i] == 'S':
			x -= 1
		if s[i] == 'E':
			y += 1
		if s[i] == 'W':
			y -= 1
		if (x, y, px, py) in path or (px, py, x, y) in path:
			cost += 1
		else:
			cost += 5
			path[x, y, px, py] = 1
	print(cost)


def move(char):
	global x
	global y
	if char == 'N':
		y += 1
	elif char == 'S':
		y -= 1
	elif char == 'E':
		x -= 1
	else:
		x += 1
for i in range(int(input())):
	string = input()
	x = 0
	y = 0
	d = {}
	time = 0
	for i in string:
		prev_x = x
		prev_y = y
		move(i)
		if prev_x > x:
			if d.get(((prev_x, prev_y), (x, y)), False):
				time += 1
			else:
				time += 5
				d[(prev_x, prev_y), (x, y)] = 1
		elif prev_x == x:
			if prev_y > y:
				if d.get(((prev_x, prev_y), (x, y)), False):
					time += 1
				else:
					time += 5
					d[(prev_x, prev_y), (x, y)] = 1
			elif d.get(((x, y), (prev_x, prev_y)), False):
				time += 1
			else:
				time += 5
				d[(x, y), (prev_x, prev_y)] = 1
		elif d.get(((x, y), (prev_x, prev_y)), False):
			time += 1
		else:
			time += 5
			d[(x, y), (prev_x, prev_y)] = 1
	print(time)


def fun(string):
	stack = set()
	x = 0
	y = 0
	path = 0
	x1 = 0
	y1 = 0
	for ch in string:
		if ch == 'W':
			x = x - 1
		if ch == 'E':
			x = x + 1
		if ch == 'N':
			y = y + 1
		if ch == 'S':
			y = y - 1
		if (x1, y1, x, y) in stack:
			path = path + 1
		else:
			path = path + 5
			stack.add((x1, y1, x, y))
			stack.add((x, y, x1, y1))
		x1 = x
		y1 = y
	print(path)
	return
for i in range(0, int(input())):
	string = input()
	fun(string)


def answer(s):
	x = 0
	y = 0
	d = {}
	time = 0
	for i in range(len(s)):
		if s[i] == 'E':
			k = [x, y]
			t = [x, y]
			x += 1
			k = tuple(k + [x, y])
			t = tuple([x, y] + t)
			if k in d or t in d:
				time += 1
			else:
				time += 5
				d[k] = 1
				d[t] = 1
		elif s[i] == 'W':
			k = [x, y]
			t = [x, y]
			x -= 1
			k = tuple(k + [x, y])
			t = tuple([x, y] + t)
			if k in d or t in d:
				time += 1
			else:
				time += 5
				d[k] = 1
				d[t] = 1
		elif s[i] == 'N':
			k = [x, y]
			t = [x, y]
			y += 1
			k = tuple(k + [x, y])
			t = tuple([x, y] + t)
			if k in d or t in d:
				time += 1
			else:
				time += 5
				d[k] = 1
				d[t] = 1
		elif s[i] == 'S':
			k = [x, y]
			t = [x, y]
			y -= 1
			k = tuple(k + [x, y])
			t = tuple([x, y] + t)
			if k in d or t in d:
				time += 1
			else:
				time += 5
				d[k] = 1
				d[t] = 1
	return time
t = int(input())
for i in range(t):
	s = input()
	print(answer(s))


t = int(input())
for y in range(t):
	s = input()
	ct = 0
	n = dict()
	e = dict()
	w = dict()
	ss = dict()
	(x, y) = (0, 0)
	for i in s:
		(dx, dy) = (x, y)
		if i == 'N':
			dx += 1
			if (x, y) in ss or (dx, dy) in n:
				ct += 1
			else:
				ct += 5
				n[dx, dy] = 1
		if i == 'E':
			dy += 1
			if (x, y) in w or (dx, dy) in e:
				ct += 1
			else:
				ct += 5
				e[dx, dy] = 1
		if i == 'W':
			dy -= 1
			if (x, y) in e or (dx, dy) in w:
				ct += 1
			else:
				ct += 5
				w[dx, dy] = 1
		if i == 'S':
			dx -= 1
			if (x, y) in n or (dx, dy) in ss:
				ct += 1
			else:
				ct += 5
				ss[dx, dy] = 1
		x = dx
		y = dy
	print(ct)


for case in range(int(input())):
	path = input()
	cur = [0, 0]
	ans = 0
	all_routes = set()
	for i in path:
		curx = cur[:]
		if i == 'N':
			cur[0] += 1
		elif i == 'S':
			cur[0] -= 1
		elif i == 'E':
			cur[1] += 1
		elif i == 'W':
			cur[1] -= 1
		if tuple(curx + cur) in all_routes or tuple(cur + curx) in all_routes:
			ans += 1
		else:
			ans += 5
			all_routes.add(tuple(cur + curx))
	print(ans)


t = int(input())

def solve(s):
	(r, c) = (0, 0)
	out = 0
	visited = set()
	visited.add((r, c))
	for ch in s:
		p1 = (r, c)
		if ch == 'N':
			r += 1
		elif ch == 'E':
			c += 1
		elif ch == 'S':
			r -= 1
		elif ch == 'W':
			c -= 1
		p2 = (r, c)
		if (p1, p2) in visited:
			out += 1
		else:
			out += 5
			visited.add((p1, p2))
			visited.add((p2, p1))
	return out
for i in range(t):
	print(solve(input()))


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for tt in range(int(input())):
	s = input()
	ans = 0
	start = [0, 0]
	d = set()
	for i in s:
		prev = list(start)
		if i == 'N':
			start[1] += 1
		elif i == 'S':
			start[1] -= 1
		elif i == 'E':
			start[0] += 1
		else:
			start[0] -= 1
		temp = tuple(prev + start)
		temp2 = tuple(start + prev)
		if temp in d or temp2 in d:
			ans += 1
		else:
			ans += 5
			d.add(temp)
			d.add(temp2)
	print(ans)


for T in range(int(input())):
	paths = set()
	x_coord = 0
	y_coord = 0
	directions = input()
	time = 0
	for dir in directions:
		if dir == 'N':
			path = ((x_coord, y_coord), (x_coord, y_coord + 1))
			y_coord += 1
		elif dir == 'S':
			path = ((x_coord, y_coord), (x_coord, y_coord - 1))
			y_coord -= 1
		elif dir == 'E':
			path = ((x_coord, y_coord), (x_coord + 1, y_coord))
			x_coord += 1
		elif dir == 'W':
			path = ((x_coord, y_coord), (x_coord - 1, y_coord))
			x_coord -= 1
		inv_path = (path[1], path[0])
		if path in paths or inv_path in paths:
			time += 1
		else:
			time += 5
			paths.add(path)
	print(time)


from math import sqrt
t = int(input())
for i in range(t):
	s = input()
	path = dict()
	time = 0
	initial_pos = [0, 0]
	for i in s:
		if i == 'N':
			final_pos = [initial_pos[0], initial_pos[1] + 1]
		if i == 'S':
			final_pos = [initial_pos[0], initial_pos[1] - 1]
		if i == 'W':
			final_pos = [initial_pos[0] - 1, initial_pos[1]]
		if i == 'E':
			final_pos = [initial_pos[0] + 1, initial_pos[1]]
		check = str(initial_pos[0]) + ',' + str(initial_pos[1]) + ',' + str(final_pos[0]) + ',' + str(final_pos[1])
		checkrev = str(final_pos[0]) + ',' + str(final_pos[1]) + ',' + str(initial_pos[0]) + ',' + str(initial_pos[1])
		if check in path:
			time += 1
		else:
			path[check] = 1
			path[checkrev] = 1
			time += 5
		initial_pos = final_pos
	print(time)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		s = rs()
		h = 0
		v = 0
		c = 0
		d = {}
		for i in s:
			(prevx, prevy) = (h, v)
			if i == 'N':
				v += 1
			if i == 'S':
				v -= 1
			if i == 'W':
				h -= 1
			if i == 'E':
				h += 1
			if (prevx, prevy, h, v) in d or (h, v, prevx, prevy) in d:
				c += 1
			else:
				c += 5
				d[prevx, prevy, h, v] = 1
		print(c)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


dir = {'N': (1, 0), 'S': (-1, 0), 'E': (0, -1), 'W': (0, 1)}
for i in range(int(input())):
	(x, y) = (0, 0)
	s = set()
	r = 0
	for c in input():
		(dx, dy) = dir[c]
		m = (x + dx, y + dy)
		if m in s:
			r += 1
		else:
			r += 5
		s.add(m)
		x += dx * 2
		y += dy * 2
	print(r)


def move(x, y, m):
	if m == 'N':
		return (x, y + 1)
	elif m == 'S':
		return (x, y - 1)
	elif m == 'E':
		return (x + 1, y)
	else:
		return (x - 1, y)
t = int(input())
for _ in range(t):
	s = input()
	visited = set()
	cnt = 0
	x = y = 0
	for c in s:
		(x2, y2) = move(x, y, c)
		seg1 = (x, y, x2, y2)
		seg2 = (x2, y2, x, y)
		if seg1 not in visited and seg2 not in visited:
			cnt += 5
			visited.add(seg1)
		else:
			cnt += 1
		(x, y) = (x2, y2)
	print(cnt)


for _ in range(int(input())):
	a = input().strip()
	n = len(a)
	x = y = 0
	b = set()
	t = 0
	for i in range(n):
		p = x
		q = y
		if a[i] == 'N':
			y += 1
		elif a[i] == 'S':
			y -= 1
		elif a[i] == 'E':
			x += 1
		else:
			x -= 1
		if (x, y, p, q) in b or (p, q, x, y) in b:
			t += 1
		else:
			t += 5
			b.add((x, y, p, q))
	print(t)


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)


import os
import heapq
import sys, threading
import math as mt
import operator
from copy import copy
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		s = input()
		(x, y) = (0, 0)
		prev = (x, y)
		ans = 0
		d = {}
		for i in s:
			if i == 'N':
				y += 1
			if i == 'S':
				y -= 1
			if i == 'W':
				x -= 1
			if i == 'E':
				x += 1
			cur = (x, y)
			if (cur, prev) in d or (prev, cur) in d:
				ans += 1
			else:
				ans += 5
				d[cur, prev] = True
				d[prev, cur] = True
			prev = cur
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
dir = {'N': (-1, 0), 'S': (1, 0), 'W': (0, -1), 'E': (0, 1)}
for _ in range(n):
	path = input()
	st = set()
	(x, y) = (0, 0)
	st.add((x, y, x, y))
	s = 0
	for ch in path:
		(nx, ny) = (x + dir[ch][0], y + dir[ch][1])
		if (x, y, nx, ny) in st:
			s += 1
		else:
			s += 5
		st.add((x, y, nx, ny))
		st.add((nx, ny, x, y))
		(x, y) = (nx, ny)
	print(s)


t = int(input())
for i in range(t):
	L = input()
	x = 0
	y = 0
	xx = 0
	yy = 0
	use = {(0, 0, 0, 0)}
	ans = 0
	for l in L:
		if l == 'N':
			yy = yy + 1
		if l == 'S':
			yy = yy - 1
		if l == 'W':
			xx = xx - 1
		if l == 'E':
			xx = xx + 1
		if (x, y, xx, yy) in use or (xx, yy, x, y) in use:
			ans = ans + 1
		else:
			ans = ans + 5
			use.add((x, y, xx, yy))
		x = xx
		y = yy
	print(ans)


n = int(input())
for i in range(n):
	st = input()
	st = list(st)
	count = 0
	liste = [0, 0]
	visited = set()
	count = 0
	for j in range(len(st)):
		lis = liste[:]
		if st[j] == 'N':
			liste[0] += 1
		if st[j] == 'S':
			liste[0] -= 1
		if st[j] == 'W':
			liste[1] += 1
		if st[j] == 'E':
			liste[1] -= 1
		if tuple(lis + liste) in visited or tuple(liste + lis) in visited:
			count += 1
		else:
			count += 5
			visited.add(tuple(lis + liste))
	print(count)


import sys
n_cases = int(next(sys.stdin))
for case in sys.stdin:
	n_cases -= 1
	visited = set()
	pos = (0, 0)
	t = 0
	for char in case.strip():
		delta = {'S': (0, -1), 'N': (0, 1), 'W': (-1, 0), 'E': (1, 0)}[char]
		npos = (pos[0] + delta[0], pos[1] + delta[1])
		segment = tuple(sorted((pos, npos)))
		pos = npos
		t += 1 + 4 * (segment not in visited)
		visited.add(segment)
	print(t)
assert n_cases == 0


for _ in range(int(input())):
	s = input()
	d = set()
	(x, y) = (0, 0)
	ans = 0
	for i in s:
		(cx, cy) = (x, y)
		if i == 'N':
			(x, y) = (x, y + 1)
		elif i == 'S':
			(x, y) = (x, y - 1)
		elif i == 'E':
			(x, y) = (x + 1, y)
		elif i == 'W':
			(x, y) = (x - 1, y)
		tp = tuple(sorted([(cx, cy), (x, y)]))
		if tp in d:
			ans += 1
		else:
			ans += 5
			d.add(tp)
	print(ans)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
for _ in range(ii()):
	s = input()
	d = dict()
	m = {'W': (-1, 0), 'N': (0, 1), 'S': (0, -1), 'E': (1, 0)}
	x = y = 10 ** 5 + 1
	res = 0
	for c in s:
		(a, b) = m[c]
		u = (x, y)
		v = (x + a, y + b)
		f = u in d and v in d[u] or (v in d and u in d[v])
		res += 1 if f else 5
		if u in d:
			d[u].add(v)
		else:
			d[u] = {v}
		if v in d:
			d[v].add(u)
		else:
			d[v] = {u}
		(x, y) = v
	print(res)


d = {'N': (0, 1), 'S': (0, -1), 'W': (-1, 0), 'E': (1, 0)}
for i in range(int(input())):
	s = input()
	t = set()
	(x, y) = (0, 0)
	time = 0
	for j in s:
		x1 = x + d[j][0]
		y1 = y + d[j][1]
		if (x, y, x1, y1) in t:
			time += 1
		else:
			time += 5
			t.add((x, y, x1, y1))
			t.add((x1, y1, x, y))
		(x, y) = (x1, y1)
	print(time)


tc = int(input())
for _ in range(tc):
	dirs = list(input())
	paths = set()
	time = 0
	x = 0
	y = 0
	for d in dirs:
		newX = x
		newY = y
		if d == 'N':
			newY += 1
		elif d == 'S':
			newY -= 1
		elif d == 'E':
			newX += 1
		else:
			newX -= 1
		if (x, y, newX, newY) in paths:
			time += 1
		else:
			time += 5
			paths.add((x, y, newX, newY))
			paths.add((newX, newY, x, y))
		x = newX
		y = newY
	print(time)


for _ in range(int(input())):
	s = input()
	st = set([(0, 0)])
	curr = [0, 0]
	ct = 0
	for i in s:
		prev = list(curr)
		if i == 'N':
			curr[1] += 1
		if i == 'S':
			curr[1] -= 1
		if i == 'W':
			curr[0] -= 1
		if i == 'E':
			curr[0] += 1
		path = tuple(sorted((tuple(prev), tuple(curr))))
		if path in st:
			ct += 1
		else:
			ct += 5
			st.add(path)
	print(ct)


import sys
t = int(sys.stdin.readline())
for j in range(t):
	route = list(str(sys.stdin.readline()))
	wasThere = dict()
	cur_state = [0, 0]
	time = int(0)
	for direction in route:
		if direction == 'N':
			vec = ('y', cur_state[0], cur_state[1])
			cur_state[1] += 1
		elif direction == 'S':
			vec = ('y', cur_state[0], cur_state[1] - 1)
			cur_state[1] -= 1
		elif direction == 'W':
			vec = ('x', cur_state[0] - 1, cur_state[1])
			cur_state[0] -= 1
		elif direction == 'E':
			vec = ('x', cur_state[0], cur_state[1])
			cur_state[0] += 1
		else:
			continue
		if vec in wasThere:
			time += 1
		else:
			time += 5
			wasThere[vec] = True
	print(time)


n = int(input())
for i in range(n):
	d = {}
	pos = (0, 0)
	s = input()
	total = 0
	for char in s:
		if char == 'N':
			new_pos = (pos[0] + 1, pos[1])
		if char == 'S':
			new_pos = (pos[0] - 1, pos[1])
		if char == 'E':
			new_pos = (pos[0], pos[1] + 1)
		if char == 'W':
			new_pos = (pos[0], pos[1] - 1)
		if (pos, new_pos) in d or (new_pos, pos) in d:
			total += 1
		else:
			total += 5
			d[pos, new_pos] = 'x'
			d[new_pos, pos] = 'x'
		pos = new_pos
	print(total)


sides = {'S': [0, -1], 'N': [0, 1], 'W': [-1, 0], 'E': [1, 0]}
s = {'S': 'N', 'N': 'S', 'W': 'E', 'E': 'W'}
for i in range(int(input())):
	sl = {'S': set(), 'N': set(), 'W': set(), 'E': set()}
	cur = [0, 0]
	l = 0
	w = input()
	for ch in w:
		if (cur[0], cur[1]) in sl[ch]:
			l += 1
			cur = list(map(lambda x, y: x + y, cur, sides[ch]))
		else:
			l += 5
			sl[ch].add((cur[0], cur[1]))
			cur = list(map(lambda x, y: x + y, cur, sides[ch]))
			sl[s[ch]].add((cur[0], cur[1]))
	print(l)


T = int(input())
for cas in range(T):
	s = input()
	(Set1, Set2) = (set(), set())
	(x, y, ans) = (0, 0, 0)
	for i in s:
		if i == 'N':
			y += 1
			if (x, y) in Set1:
				ans += 1
			else:
				ans += 5
			Set1.add((x, y))
		elif i == 'S':
			if (x, y) in Set1:
				ans += 1
			else:
				ans += 5
			Set1.add((x, y))
			y -= 1
		elif i == 'W':
			if (x, y) in Set2:
				ans += 1
			else:
				ans += 5
			Set2.add((x, y))
			x -= 1
		else:
			x += 1
			if (x, y) in Set2:
				ans += 1
			else:
				ans += 5
			Set2.add((x, y))
	print(ans)


t = int(input())
for i in range(t):
	string = list(input())
	time = 0
	flag = True
	visited = {(0, 0): [string[0]]}
	position = (0, 0)
	compare = ['N', 'S', 'E', 'W']
	number = 0
	for i in string:
		if i not in visited[position]:
			visited[position].append(i)
		if i == 'N':
			number = 1
			position = (position[0] + 1, position[1])
		elif i == 'S':
			number = 0
			position = (position[0] - 1, position[1])
		elif i == 'E':
			number = 3
			position = (position[0], position[1] + 1)
		elif i == 'W':
			number = 2
			position = (position[0], position[1] - 1)
		if position in visited:
			if compare[number] in visited[position]:
				time += 1
			else:
				visited[position].append(compare[number])
				time += 5
		else:
			visited[position] = [compare[number]]
			time += 5
	print(time)


for _ in range(int(input())):
	(x, y) = (0, 0)
	paths = set()
	score = 0
	for c in input():
		if c == 'E':
			(dx, dy) = (1, 0)
		elif c == 'W':
			(dx, dy) = (-1, 0)
		elif c == 'N':
			(dx, dy) = (0, 1)
		else:
			(dx, dy) = (0, -1)
		p = [(x, y), (x + dx, y + dy)]
		p = tuple(sorted(p))
		if p in paths:
			score += 1
		else:
			score += 5
			paths.add(p)
		(x, y) = (x + dx, y + dy)
	print(score)


for _ in range(int(input())):
	l = set()
	a = (0, 0)
	c = 0
	for i in input():
		if i == 'N':
			b = (a[0], a[1] + 1)
		elif i == 'W':
			b = (a[0] - 1, a[1])
		elif i == 'S':
			b = (a[0], a[1] - 1)
		elif i == 'E':
			b = (a[0] + 1, a[1])
		if a + b not in l:
			c += 5
		else:
			c += 1
		l.add(a + b)
		l.add(b + a)
		a = b
	print(c)


import sys
import os
import heapq
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass
for _ in range(t):
	path = input()
	currentx = 100000
	currenty = 100000
	map = {}
	result = 0
	for c in path:
		pospre = currentx * 1000000 + currenty
		dir = 0
		if c == 'N':
			currenty += 1
			dir = 1
		if c == 'S':
			currenty -= 1
			dir = 3
		if c == 'W':
			currentx -= 1
			dir = 4
		if c == 'E':
			currentx += 1
			dir = 0
		pospre = pospre * 10 + (4 - dir)
		pos = currentx * 1000000 + currenty
		pos = pos * 10 + dir
		if pos in map:
			result += 1
		else:
			map[pos] = True
			result += 5
		map[pospre] = True
	print(result)


def getLines(num, p):
	n = num if num <= pow(10, p) else pow(10, p)
	inputLines = []
	for i in range(0, n):
		line = input()
		if line:
			inputLines.append(line)
		else:
			break
	return inputLines

def notZeroPow(num, p):
	return True if num >= 1 and num <= pow(10, p) else False

def minPair(a, b):
	return a if a[0] + a[1] < b[0] + b[1] else b

def maxPair(a, b):
	return a if a[0] + a[1] > b[0] + b[1] else b

def setAdd(s, x):
	l = len(s)
	s.add(x)
	return len(s) != l

def getSum(text):
	points = {}
	cur = [0, 0]
	sum = 0
	for c in text:
		nxt = [cur[0], cur[1]]
		if c == 'N':
			nxt[0] += 1
		if c == 'S':
			nxt[0] -= 1
		if c == 'W':
			nxt[1] += 1
		if c == 'E':
			nxt[1] -= 1
		l = minPair(cur, nxt)
		h = maxPair(cur, nxt)
		sp = str(l[0]) + str(l[1]) + str(h[0]) + str(h[1])
		if not sp in points:
			sum += 5
			points[sp] = 1
		else:
			sum += 1
		cur = [nxt[0], nxt[1]]
	return sum
rc = int(input())
lines = getLines(rc, 4)
results = []
for e in lines:
	sum = getSum(e)
	results.append(sum)
for e in results:
	print(e)


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)


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
mp = lambda : map(int, input().split())
for _ in range(int(input())):
	d = input()
	dt = {'N': [0, 1], 'S': [0, -1], 'W': [-1, 0], 'E': [1, 0]}
	st = set()
	st.add((0, 0))
	(x, y) = (0, 0)
	ctr = 0
	for i in d:
		(a, b) = (x + dt[i][0], y + dt[i][1])
		if (x, y, a, b) in st or (a, b, x, y) in st:
			ctr += 1
		else:
			ctr += 5
			st.add((x, y, a, b))
			st.add((a, b, x, y))
		(x, y) = (a, b)
	print(ctr)


for t in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	time = 0
	table = {}
	for c in s:
		if c == 'N':
			if (x, y, x, y + 1) in table or (x, y + 1, x, y) in table:
				time += 1
			else:
				table[x, y, x, y + 1] = 1
				time += 5
			y += 1
		elif c == 'S':
			if (x, y, x, y - 1) in table or (x, y - 1, x, y) in table:
				time += 1
			else:
				table[x, y, x, y - 1] = 1
				time += 5
			y -= 1
		elif c == 'E':
			if (x, y, x + 1, y) in table or (x + 1, y, x, y) in table:
				time += 1
			else:
				table[x, y, x + 1, y] = 1
				time += 5
			x += 1
		else:
			if (x, y, x - 1, y) in table or (x - 1, y, x, y) in table:
				time += 1
			else:
				table[x - 1, y, x, y] = 1
				time += 5
			x -= 1
	print(time)


for _ in range(int(input())):
	path = set()
	(x, y) = (0, 0)
	s = input()
	ans = 0
	for i in s:
		if i == 'N':
			if ((x, y), (x, y + 1)) not in path and ((x, y + 1), (x, y)) not in path:
				path.add(((x, y + 1), (x, y)))
				y += 1
				ans += 5
			else:
				y += 1
				ans += 1
		elif i == 'S':
			if ((x, y), (x, y - 1)) not in path and ((x, y - 1), (x, y)) not in path:
				path.add(((x, y - 1), (x, y)))
				y -= 1
				ans += 5
			else:
				y -= 1
				ans += 1
		elif i == 'E':
			if ((x + 1, y), (x, y)) not in path and ((x, y), (x + 1, y)) not in path:
				path.add(((x + 1, y), (x, y)))
				x += 1
				ans += 5
			else:
				x += 1
				ans += 1
		elif i == 'W':
			if ((x - 1, y), (x, y)) not in path and ((x, y), (x - 1, y)) not in path:
				path.add(((x - 1, y), (x, y)))
				x -= 1
				ans += 5
			else:
				x -= 1
				ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	a = input()
	sum = 0
	s = set()
	x = 0
	y = 0
	for i in range(len(a)):
		x1 = x
		y1 = y
		if a[i] == 'N':
			y += 1
		elif a[i] == 'S':
			y -= 1
		elif a[i] == 'E':
			x += 1
		else:
			x -= 1
		if (x, y, x1, y1) in s or (x1, y1, x, y) in s:
			sum += 1
		else:
			sum += 5
			s.add((x, y, x1, y1))
			s.add((x1, y1, x, y))
	print(sum)


for _ in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	st = set()
	t = 0
	for i in s:
		initial = str([x, y])
		if i == 'N':
			y += 1
		if i == 'S':
			y -= 1
		if i == 'E':
			x += 1
		if i == 'W':
			x -= 1
		final = str([x, y])
		(a, b) = (initial + ',' + final, final + ',' + initial)
		if a in st or b in st:
			t += 1
		else:
			t += 5
			st.add(a)
			st.add(b)
	print(t)


from collections import defaultdict
t = int(input())
while t > 0:
	t -= 1
	s = input()
	visited = dict()
	visited = defaultdict(lambda : False, visited)
	x = 0
	y = 0
	cost = 0
	for i in s:
		if i == 'E':
			if visited[x + 1, y, 'E'] or visited[x, y, 'W']:
				cost += 1
			else:
				visited[x + 1, y, 'E'] = True
				visited[x, y, 'W'] = True
				cost += 5
			x += 1
		elif i == 'W':
			if visited[x - 1, y, 'W'] or visited[x, y, 'E']:
				cost += 1
			else:
				visited[x - 1, y, 'W'] = True
				visited[x, y, 'E'] = True
				cost += 5
			x -= 1
		elif i == 'N':
			if visited[x, y + 1, 'N'] or visited[x, y, 'S']:
				cost += 1
			else:
				visited[x, y + 1, 'N'] = True
				visited[x, y, 'S'] = True
				cost += 5
			y += 1
		elif i == 'S':
			if visited[x, y - 1, 'S'] or visited[x, y, 'N']:
				cost += 1
			else:
				visited[x, y - 1, 'S'] = True
				visited[x, y, 'N'] = True
				cost += 5
			y -= 1
	print(cost)


num_tests = int(input())
tests = []
time_records = []

def compare(a, b):
	if a > b:
		return a
	else:
		return b
for i in range(num_tests):
	tests.append(input())
for string in tests:
	visited_set = set([])
	len_string = len(string)
	position = [0, 0]
	timer = 0
	for j in range(len(string)):
		if string[j] == 'N':
			point1 = str(position[0]) + ':' + str(position[1])
			point2 = str(position[0]) + ':' + str(position[1] + 1)
			direction = point1 + '->' + point2
			reversed_direction = point2 + '->' + point1
			if direction not in visited_set:
				visited_set.add(direction)
				visited_set.add(reversed_direction)
				timer = timer + 5
			else:
				timer = timer + 1
			position[1] = position[1] + 1
		elif string[j] == 'S':
			point1 = str(position[0]) + ':' + str(position[1])
			point2 = str(position[0]) + ':' + str(position[1] - 1)
			direction = point1 + '->' + point2
			reversed_direction = point2 + '->' + point1
			if direction not in visited_set:
				visited_set.add(direction)
				visited_set.add(reversed_direction)
				timer = timer + 5
			else:
				timer = timer + 1
			position[1] = position[1] - 1
		elif string[j] == 'W':
			point1 = str(position[0]) + ':' + str(position[1])
			point2 = str(position[0] - 1) + ':' + str(position[1])
			direction = point1 + '->' + point2
			reversed_direction = point2 + '->' + point1
			if direction not in visited_set:
				visited_set.add(direction)
				visited_set.add(reversed_direction)
				timer = timer + 5
			else:
				timer = timer + 1
			position[0] = position[0] - 1
		elif string[j] == 'E':
			point1 = str(position[0]) + ':' + str(position[1])
			point2 = str(position[0] + 1) + ':' + str(position[1])
			direction = point1 + '->' + point2
			reversed_direction = point2 + '->' + point1
			if direction not in visited_set:
				visited_set.add(direction)
				visited_set.add(reversed_direction)
				timer = timer + 5
			else:
				timer = timer + 1
			position[0] = position[0] + 1
	time_records.append(timer)
for i in time_records:
	print(i)


import sys
import os
from io import BytesIO, IOBase

def cel(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
for _ in range(ii()):
	dx = {'S': 0, 'N': 0, 'E': 1, 'W': -1}
	dy = {'S': -1, 'N': 1, 'E': 0, 'W': 0}
	s = input()
	st = set()
	(x, y) = (0, 0)
	ans = 0
	for i in s:
		tmpx = x
		tmpy = y
		x += dx[i]
		y += dy[i]
		if ((x, y), (tmpx, tmpy)) in st or ((tmpx, tmpy), (x, y)) in st:
			ans += 1
		else:
			ans += 5
		st.add(((tmpx, tmpy), (x, y)))
	print(ans)


def solve():
	t = int(input())
	for _ in range(t):
		ans = 0
		p = set()
		path = input()
		cur_pos = (0, 0)
		for move in path:
			next_pos = None
			if move == 'N':
				next_pos = (cur_pos[0], cur_pos[1] + 1)
			elif move == 'W':
				next_pos = (cur_pos[0] - 1, cur_pos[1])
			elif move == 'S':
				next_pos = (cur_pos[0], cur_pos[1] - 1)
			elif move == 'E':
				next_pos = (cur_pos[0] + 1, cur_pos[1])
			edge = None
			if cur_pos < next_pos:
				edge = (cur_pos, next_pos)
			else:
				edge = (next_pos, cur_pos)
			if edge not in p:
				ans += 5
			else:
				ans += 1
			p.add(edge)
			cur_pos = next_pos
		print(ans)
solve()


for _ in range(int(input())):
	word = input()
	cur = (0, 0)
	d = {}
	ans = 0
	for i in word:
		(x, y) = (cur[0], cur[1])
		if i == 'N':
			x += 1
		elif i == 'S':
			x -= 1
		elif i == 'E':
			y += 1
		else:
			y -= 1
		l = (cur[0], cur[1], x, y)
		p = (x, y, cur[0], cur[1])
		cur = (x, y)
		if l not in d and p not in d:
			ans += 5
		else:
			ans += 1
		d[p] = 1
		d[l] = 1
	print(ans)


t = int(input())
for i in range(t):
	st = input()
	x = 0
	y = 0
	summ = 0
	d = {}
	l = len(st)
	for i in range(0, l):
		px = x
		py = y
		if st[i] == 'N':
			x = x + 1
		if st[i] == 'S':
			x = x - 1
		if st[i] == 'E':
			y = y + 1
		if st[i] == 'W':
			y = y - 1
		if (px, py, x, y) in d or (x, y, px, py) in d:
			summ += 1
		else:
			summ += 5
			d[px, py, x, y] = 1
			d[x, y, px, py] = 1
	print(summ)


t = int(input())
for i in range(t):
	s = input()
	y = 0
	x = 0
	a = dict()
	j = 0
	p = 0
	while j < len(s):
		m = x
		n = y
		if s[j] == 'N':
			x += 1
			if (m, y, x, y) in a.keys():
				p += 1
			else:
				p += 5
				a[m, n, x, y] = 1
		elif s[j] == 'S':
			x += -1
			if (x, y, m, n) in a.keys():
				p += 1
			else:
				p += 5
				a[x, n, m, y] = 1
		elif s[j] == 'E':
			y += 1
			if (x, n, m, y) in a.keys():
				p += 1
			else:
				p += 5
				a[x, n, m, y] = 1
		elif s[j] == 'W':
			y += -1
			if (x, y, m, n) in a.keys():
				p += 1
			else:
				p += 5
				a[x, y, m, n] = 1
		j += 1
	print(p)


from sys import stdin
for _ in range(int(input())):
	d = {}
	start = [0, 0]
	r = 0
	l = stdin.readline().rstrip()
	for i in l:
		if i == 'N':
			end = [start[0] + 1, start[1]]
			path = str(sorted([start, end]))
			if not d.get(path, 0):
				d[path] = 0
			d[path] += 1
			if d[path] == 1:
				r += 5
			else:
				r += 1
			start = end
		elif i == 'S':
			end = [start[0] - 1, start[1]]
			path = str(sorted([start, end]))
			if not d.get(path, 0):
				d[path] = 0
			d[path] += 1
			if d[path] == 1:
				r += 5
			else:
				r += 1
			start = end
		elif i == 'W':
			end = [start[0], start[1] - 1]
			path = str(sorted([start, end]))
			if not d.get(path, 0):
				d[path] = 0
			d[path] += 1
			if d[path] == 1:
				r += 5
			else:
				r += 1
			start = end
		elif i == 'E':
			end = [start[0], start[1] + 1]
			path = str(sorted([start, end]))
			if not d.get(path, 0):
				d[path] = 0
			d[path] += 1
			if d[path] == 1:
				r += 5
			else:
				r += 1
			start = end
	print(r)


from collections import defaultdict as dd
for _ in range(int(input())):
	s = input()
	curx = 0
	cury = 0
	d = dd(int)
	for i in s:
		save = (curx, cury)[:]
		if i == 'N':
			cury += 1
		elif i == 'S':
			cury -= 1
		elif i == 'E':
			curx += 1
		else:
			curx -= 1
		d[tuple(sorted((save, (curx, cury))))] += 1
	ans = 0
	for i in d:
		ans += d[i] - 1 + 5
	print(ans)


def count_seconds(s):
	c = 0
	(x, y) = (0, 0)
	paths = {}
	for i in range(0, len(s)):
		pre_x = x
		pre_y = y
		if s[i] == 'S':
			y -= 1
		elif s[i] == 'N':
			y += 1
		elif s[i] == 'W':
			x -= 1
		elif s[i] == 'E':
			x += 1
		if (x, y) in paths:
			if (pre_x, pre_y) in paths[x, y]:
				c += 1
			else:
				c += 5
				paths[x, y].append((pre_x, pre_y))
		else:
			c += 5
			paths[x, y] = [(pre_x, pre_y)]
		if (pre_x, pre_y) in paths:
			if (x, y) not in paths[pre_x, pre_y]:
				paths[pre_x, pre_y].append((x, y))
		else:
			paths[pre_x, pre_y] = [(x, y)]
	return c
t = int(input())
for _ in range(t):
	s = input()
	print(count_seconds(s))


numcases = int(input())
for i in range(numcases):
	visit = {}
	s = input()
	p1 = 0
	p2 = 0
	count = 0
	for i in range(len(s)):
		(prev1, prev2) = (p1, p2)
		if s[i] == 'N':
			p1 += 1
		if s[i] == 'S':
			p1 -= 1
		if s[i] == 'E':
			p2 += 1
		if s[i] == 'W':
			p2 -= 1
		if tuple([prev1, prev2, p1, p2]) not in visit:
			visit[tuple([prev1, prev2, p1, p2])] = 0
			visit[tuple([p1, p2, prev1, prev2])] = 0
			count += 5
		else:
			count += 1
	print(count)


T = int(input())
for t in range(T):
	tmp = input()
	d = dict()
	(x, y) = (0, 0)
	tim = 0
	for direction in tmp:
		(x0, y0) = (x, y)
		if direction == 'N':
			y += 1
		elif direction == 'S':
			y -= 1
		elif direction == 'W':
			x -= 1
		elif direction == 'E':
			x += 1
		else:
			continue
		if ((x, y), (x0, y0)) in d or ((x0, y0), (x, y)) in d:
			tim += 1
		else:
			tim += 5
			d[(x0, y0), (x, y)] = 1
	print(tim)


for _ in range(int(input())):
	st = input()
	se = set({})
	x = 0
	y = 0
	ans = 0
	prev = '0@0'
	for i in st:
		if i == 'E':
			x += 1
		elif i == 'W':
			x -= 1
		elif i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		iid = str(x) + '@' + str(y)
		path = prev + '@@' + iid
		rev = iid + '@@' + prev
		if path in se or rev in se:
			ans += 1
		else:
			se.add(rev)
			se.add(path)
			ans += 5
		prev = iid
	print(ans)


from collections import defaultdict

def solve(path):
	(x, y, count) = (0, 0, 0)
	stored = defaultdict(lambda : defaultdict(lambda : ''))
	for p in path:
		new_x = x + 1 if p == 'E' else x - 1 if p == 'W' else x
		new_y = y + 1 if p == 'N' else y - 1 if p == 'S' else y
		(x_pos, y_pos) = ((x + new_x) / 2, (y + new_y) / 2)
		(x, y) = (new_x, new_y)
		count += 1
		if p not in stored[x_pos][y_pos]:
			count += 4
			stored[x_pos][y_pos] += 'NS' if p in 'NS' else 'WE'
	return count
for _ in range(int(input())):
	print(solve(input()))


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):
	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
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:

	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]

	def query(self, l, r):
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][r - (1 << N)])

	def query_id(self, l, r):
		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)
	print(ans)


t = int(input())
for i in range(t):
	s = str(input())
	n = len(s)
	lis = [0, 0]
	dict = {}
	ans = 0
	for j in range(n):
		tuple1 = (lis[0], lis[1])
		if s[j] == 'W':
			lis[0] -= 1
		if s[j] == 'E':
			lis[0] += 1
		if s[j] == 'N':
			lis[1] += 1
		if s[j] == 'S':
			lis[1] -= 1
		tuple2 = (lis[0], lis[1])
		tuple3 = (tuple1, tuple2)
		tuple4 = (tuple2, tuple1)
		if tuple3 in dict.keys() or tuple4 in dict.keys():
			ans += 1
		else:
			dict[tuple3] = 1
			dict[tuple4] = 1
			ans += 5
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	l = len(s)
	visited = set()
	(x, y) = (0, 0)
	ans = 0
	for i in range(l):
		if s[i] == 'N':
			nx = x + 0
			ny = y + 1
		elif s[i] == 'E':
			nx = x + 1
			ny = y + 0
		elif s[i] == 'S':
			nx = x + 0
			ny = y - 1
		elif s[i] == 'W':
			nx = x - 1
			ny = y + 0
		if (x, y, nx, ny) in visited or (nx, ny, x, y) in visited:
			ans += 1
		else:
			ans += 5
		visited.add((x, y, nx, ny))
		visited.add((nx, ny, x, y))
		(x, y) = (nx, ny)
	print(ans)


import sys

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
t = int(input())
while t > 0:
	t -= 1
	s = list(input().rstrip())
	d = {}
	(h, v) = (0, 0)
	c = 0
	for i in s:
		(p, q) = (h, v)
		if i == 'E':
			h -= 1
		if i == 'W':
			h += 1
		if i == 'N':
			v -= 1
		if i == 'S':
			v += 1
		f = str(p) + '*' + str(q) + '*' + str(h) + '*' + str(v)
		f2 = str(h) + '*' + str(v) + '*' + str(p) + '*' + str(q)
		if f in d:
			c += 1
		else:
			c += 5
			d[f] = 1
			d[f2] = 1
	print(c)


import io
import os
from collections import Counter, defaultdict, deque
dxdy = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}

def solve(S):
	seen = set()
	(x, y) = (0, 0)
	cost = 0
	for d in S:
		(dx, dy) = dxdy[d]
		(nx, ny) = (x + dx, y + dy)
		if (x, y, nx, ny) in seen:
			cost += 1
		else:
			cost += 5
		seen.add((x, y, nx, ny))
		seen.add((nx, ny, x, y))
		(x, y) = (nx, ny)
	return cost
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	S = input().decode().rstrip()
	ans = solve(S)
	print(ans)


test = int(input())
while test:
	test -= 1
	s = input()
	x = 0
	y = 0
	ls = set()
	ans = 0
	for i in s:
		tx = x
		ty = y
		if i == 'N':
			x += 1
		if i == 'S':
			x -= 1
		if i == 'E':
			y += 1
		if i == 'W':
			y -= 1
		if tuple((tx, ty, x, y)) not in ls:
			ans += 5
			ls.add(tuple((tx, ty, x, y)))
			ls.add(tuple((x, y, tx, ty)))
		else:
			ans += 1
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	s = input()
	d = defaultdict(int)
	x = 0
	y = 0
	ans = 0
	for item in s:
		x1 = x
		y1 = y
		if item == 'N':
			x += 1
		elif item == 'S':
			x -= 1
		elif item == 'E':
			y += 1
		elif item == 'W':
			y -= 1
		if (x, y, x1, y1) in d.keys() or (x1, y1, x, y) in d.keys():
			ans += 1
		else:
			ans += 5
			d[x, y, x1, y1] = 1
	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)


for _ in range(int(input())):
	s = input()
	path = set()
	startx = 0
	starty = 0
	cost = 0
	for i in s:
		nextx = startx
		nexty = starty
		if i == 'N':
			nexty = starty + 1
		elif i == 'S':
			nexty = starty - 1
		elif i == 'E':
			nextx = startx + 1
		else:
			nextx = startx - 1
		p1 = (nextx, nexty, startx, starty)
		p2 = (startx, starty, nextx, nexty)
		if p1 in path or p2 in path:
			cost += 1
		else:
			cost += 5
		path.add(p2)
		startx = nextx
		starty = nexty
	print(cost)


t = int(input())
for _ in range(t):
	s = input()
	vis = {}
	sm = 0
	r = 0
	c = 0
	tr = {'N': (1, 0), 'S': (-1, 0), 'E': (0, 1), 'W': (0, -1)}
	for i in range(len(s)):
		nr = tr[s[i]][0] + r
		nc = tr[s[i]][1] + c
		if ((r, c), (nr, nc)) in vis:
			sm += 1
		else:
			sm += 5
		vis[(r, c), (nr, nc)] = 1
		vis[(nr, nc), (r, c)] = 1
		r = nr
		c = nc
	print(sm)


import math
from collections import Counter, deque
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()
mod = 10 ** 9 + 7

def s(a):
	print(' '.join(list(map(str, a))))
for i in range(I()):
	s = IN()
	d = {}
	(x, y) = (0, 0)
	count = 0
	d[x, y] = 1
	for i in s:
		(p, q) = (x, y)
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		else:
			x -= 1
		if (p, q, x, y) in d:
			count += 1
		else:
			count += 5
			d[p, q, x, y] = 1
			d[x, y, p, q] = 1
	print(count)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	string = input().strip()
	(p, q) = (0, 0)
	mset = set()
	ans = 0
	(x, y) = (p, q)
	for i in string:
		if i == 'N':
			y += 1
		elif i == 'E':
			x += 1
		elif i == 'S':
			y -= 1
		else:
			x -= 1
		if ((p, q), (x, y)) in mset:
			ans += 1
		else:
			ans += 5
			mset.add(((p, q), (x, y)))
			mset.add(((x, y), (p, q)))
		(p, q) = (x, y)
	print(ans)


for _ in range(int(input())):
	(s, r, c, a, m) = (input(), 0, 0, 0, set())
	for i in s:
		if i == 'N':
			i = (r, c, r, c + 1)
			c += 1
		elif i == 'S':
			i = (r, c - 1, r, c)
			c -= 1
		elif i == 'W':
			i = (r - 1, c, r, c)
			r -= 1
		elif i == 'E':
			i = (r, c, r + 1, c)
			r += 1
		if i not in m:
			a += 5
			m.add(i)
		else:
			a += 1
	print(a)


dic = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
t = int(input())
for i in range(t):
	s = input()
	s1 = set()
	(x, y, t) = (0, 0, 0)
	for j in s:
		x1 = x + dic[j][0]
		y1 = y + dic[j][1]
		if (x, y, x1, y1) in s1 or (x1, y1, x, y) in s1:
			t += 1
		else:
			t += 5
			s1.add((x, y, x1, y1))
		(x, y) = (x1, y1)
	print(t)


num = int(input())

def times(x, y, x_o, y_o, matrix):
	start = str(x) + ' ' + str(y)
	end = str(x_o) + ' ' + str(y_o)
	if (start, end) in matrix:
		return 1
	else:
		matrix.add((start, end))
		matrix.add((end, start))
		return 5
for i in range(num):
	t = 0
	x = 0
	y = 0
	road = input()
	matrix = set()
	for r in road:
		if r == 'N':
			t += times(x, y, x, y - 1, matrix)
			y -= 1
		elif r == 'S':
			t += times(x, y, x, y + 1, matrix)
			y += 1
		elif r == 'W':
			t += times(x, y, x - 1, y, matrix)
			x -= 1
		elif r == 'E':
			t += times(x, y, x + 1, y, matrix)
			x += 1
	print(t)


import collections

class Position:
	__slots__ = ('x', 'y')

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __eq__(self, other):
		return self.x == other.x and self.y == other.y

	def __hash__(self):
		return hash((self.x, self.y))

	def __repr__(self):
		return 'Position(x={}, y={})'.format(self.x, self.y)

def path_duration(path):
	position = Position(0, 0)
	position_paths = collections.defaultdict(list)
	duration = 0
	for direction in path:
		if direction == 'S':
			new_position = Position(position.x, position.y - 1)
		elif direction == 'N':
			new_position = Position(position.x, position.y + 1)
		elif direction == 'W':
			new_position = Position(position.x - 1, position.y)
		elif direction == 'E':
			new_position = Position(position.x + 1, position.y)
		if new_position in position_paths.get(position, []):
			speed = 1
		else:
			speed = 5
		duration += speed
		position_paths[position].append(new_position)
		position_paths[new_position].append(position)
		position = new_position
	return duration

def main():
	t = int(input())
	for _ in range(t):
		path = input()
		print(path_duration(path))
assert path_duration('NNN') == 15
assert path_duration('NS') == 6
assert path_duration('WWEN') == 16
assert path_duration('WWEE') == 12
assert path_duration('NWNWS') == 25
assert path_duration('ESWN') == 20
assert path_duration('WSESNN') == 26
main()


import sys

def oppDirc(c):
	if c == 'b':
		return 'u'
	elif c == 'u':
		return 'b'
	elif c == 'l':
		return 'r'
	else:
		return 'l'
t = int(input())
for i in range(t):
	s = input()
	ans = 0
	last = [0, 0]
	vis = dict()
	vis[tuple(last)] = set()
	for si in s:
		prev = last.copy()
		dirn = None
		if si == 'N':
			last[1] += 1
			dirn = 'b'
		elif si == 'E':
			last[0] += 1
			dirn = 'l'
		elif si == 'W':
			last[0] -= 1
			dirn = 'r'
		else:
			last[1] -= 1
			dirn = 'u'
		tl = tuple(last)
		tp = tuple(prev)
		if tl not in vis:
			ans += 5
			vis[tl] = set([dirn])
			vis[tp].add(oppDirc(dirn))
		elif dirn in vis[tl]:
			ans += 1
		else:
			vis[tl].add(dirn)
			vis[tp].add(oppDirc(dirn))
			ans += 5
	print(ans)


from collections import defaultdict

def solve(path):
	(x, y, c) = (0, 0, 0)
	stored = defaultdict(lambda : 5)
	for p in path:
		nx = x + 1 if p == 'E' else x - 1 if p == 'W' else x
		ny = y + 1 if p == 'N' else y - 1 if p == 'S' else y
		c += min(stored[x, y, nx, ny], stored[nx, ny, x, y])
		stored[x, y, nx, ny] = 1
		(x, y) = (nx, ny)
	return c
for _ in range(int(input())):
	print(solve(input()))


import sys
import os
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def getPath(x1, y1, x2, y2):
	return format((x1, y1, x2, y2))
test_count = int(input())
for t in range(test_count):
	moves = insr()
	cost = 0
	paths = set()
	(startX, startY, endX, endY) = (0, 0, 0, 0)
	for move in moves:
		startX = endX
		startY = endY
		if move == 'N':
			endY = startY + 1
		elif move == 'S':
			endY = startY - 1
		elif move == 'E':
			endX = startX + 1
		else:
			endX = startX - 1
		segment1 = getPath(startX, startY, endX, endY)
		segment2 = getPath(endX, endY, startX, startY)
		if segment1 in paths or segment2 in paths:
			cost += 1
		else:
			cost += 5
			paths.add(getPath(startX, startY, endX, endY))
	print(cost)


import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li1():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)
for _ in range(ii()):
	s = si()
	(x1, y1) = (0, 0)
	st = set()
	ans = 0
	for i in s:
		x2 = x1
		y2 = y1
		if i == 'N':
			y2 += 1
		elif i == 'S':
			y2 -= 1
		elif i == 'E':
			x2 += 1
		else:
			x2 -= 1
		if (x1, y1, x2, y2) in st or (x2, y2, x1, y1) in st:
			ans += 1
		else:
			ans += 5
			st.add((x1, y1, x2, y2))
		x1 = x2
		y1 = y2
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
dir = {'N': (0, 1), 'E': (1, 0), 'W': (-1, 0), 'S': (0, -1)}
for _ in range(int(input())):
	cur = (0, 0)
	ans = 0
	vis = 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())
g = {'N': (0, 1), 'W': (-1, 0), 'E': (1, 0), 'S': (0, -1)}
while t:
	slide = {}
	(pp1, pp2) = (0, 0)
	s = input()
	x = y = 0
	ans = 0
	for i in s:
		(a, b) = g[i]
		(pp1, pp2) = (x, y)
		(x, y) = (x + a, y + b)
		if slide.get(((x, y), (pp1, pp2))) or slide.get(((pp1, pp2), (x, y))):
			ans += 1
		else:
			slide[(x, y), (pp1, pp2)] = 1
			ans += 5
	print(ans)
	t -= 1


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()
	d = dict()
	(x, y) = (0, 0)
	d[0, 0, 0, 0] = 1
	t = 0
	for a in s:
		if a == 'N':
			if d.get((x, x, y, y + 1), 0) == 0:
				t += 5
			else:
				t += 1
			d[x, x, y, y + 1] = 1
			y += 1
		elif a == 'E':
			if d.get((x, x + 1, y, y), 0) == 0:
				t += 5
			else:
				t += 1
			d[x, x + 1, y, y] = 1
			x += 1
		elif a == 'W':
			if d.get((x - 1, x, y, y), 0) == 0:
				t += 5
			else:
				t += 1
			d[x - 1, x, y, y] = 1
			x -= 1
		else:
			if d.get((x, x, y - 1, y), 0) == 0:
				t += 5
			else:
				t += 1
			d[x, x, y - 1, y] = 1
			y -= 1
	print(t)


from collections import defaultdict

def dist(s):
	dic = defaultdict(int)
	p = [0, 0]
	res = 0
	for c in s:
		t = p[:]
		if c == 'E':
			t[0] = p[0] + 1
		elif c == 'W':
			t[0] = p[0] - 1
		elif c == 'N':
			t[1] = p[1] + 1
		else:
			t[1] = p[1] - 1
		d1 = (p[0], p[1], t[0], t[1])
		d2 = (t[0], t[1], p[0], p[1])
		if d1 in dic:
			res += 1
		else:
			res += 5
			dic[d2] += 1
			dic[d1] += 1
		p[0] = t[0]
		p[1] = t[1]
	return res
t = int(input())
while t:
	s = input()
	print(dist(s))
	t -= 1


t = int(input())

def solve(seq):
	(x, y) = (0, 0)
	st = {}
	tot = 0
	for c in seq:
		(a, b) = (x, y)
		if c == 'N':
			y += 1
		elif c == 'S':
			y -= 1
		elif c == 'E':
			x += 1
		elif c == 'W':
			x -= 1
		k1 = str(x) + ' ' + str(y) + ' ' + str(a) + ' ' + str(b)
		k2 = str(a) + ' ' + str(b) + ' ' + str(x) + ' ' + str(y)
		if k2 in st:
			tot += 1
		else:
			tot += 5
		st[k1] = True
		st[k2] = True
	return tot
for _ in range(t):
	print(solve(input()))


def main():
	for _ in range(int(input())):
		s = list(input())
		(x, y, su) = (0, 0, 0)
		s1 = set()
		for i in s:
			if i == 'N' and (x, y, x + 1, y) not in s1:
				x += 1
				su += 5
				s1.add((x - 1, y, x, y))
				s1.add((x, y, x - 1, y))
			elif i == 'N':
				x += 1
				su += 1
			elif i == 'S' and (x, y, x - 1, y) not in s1:
				x -= 1
				su += 5
				s1.add((x + 1, y, x, y))
				s1.add((x, y, x + 1, y))
			elif i == 'S':
				x -= 1
				su += 1
			elif i == 'E' and (x, y, x, y + 1) not in s1:
				y += 1
				su += 5
				s1.add((x, y - 1, x, y))
				s1.add((x, y, x, y - 1))
			elif i == 'E':
				y += 1
				su += 1
			if i == 'W' and (x, y, x, y - 1) not in s1:
				y -= 1
				su += 5
				s1.add((x, y + 1, x, y))
				s1.add((x, y, x, y + 1))
			elif i == 'W':
				y -= 1
				su += 1
		print(su)
main()


moves = {'N': lambda x, y: (x, y + 1), 'S': lambda x, y: (x, y - 1), 'E': lambda x, y: (x + 1, y), 'W': lambda x, y: (x - 1, y)}
t = int(input())
for _ in range(t):
	s = input()
	visited = set()
	cnt = 0
	x = y = 0
	for c in s:
		(x2, y2) = moves[c](x, y)
		seg1 = (x, y, x2, y2)
		seg2 = (x2, y2, x, y)
		if seg1 not in visited and seg2 not in visited:
			cnt += 5
			visited.add(seg1)
		else:
			cnt += 1
		(x, y) = (x2, y2)
	print(cnt)


T = int(input())
for _ in range(0, T):
	s = input()
	kk = dict()
	ans = 0
	x = 0
	y = 0
	for i in range(0, len(s)):
		a = x
		b = y
		if s[i] == 'N':
			x += 1
		elif s[i] == 'S':
			x -= 1
		elif s[i] == 'W':
			y += 1
		else:
			y -= 1
		if kk.get(((x, y), (a, b))) == None:
			ans += 5
			kk[(x, y), (a, b)] = 1
			kk[(a, b), (x, y)] = 1
		else:
			ans += 1
	print(ans)


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

def read_ints():
	return 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)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for j in range(int(input())):
	vals = [k for k in input()]
	dict1 = {}
	x = 0
	y = 0
	time = 0
	for s in range(len(vals)):
		oldcord = (x, y)
		if vals[s] == 'N':
			y += 1
		elif vals[s] == 'S':
			y -= 1
		elif vals[s] == 'E':
			x += 1
		elif vals[s] == 'W':
			x -= 1
		if not oldcord in dict1:
			time += 5
			set1 = set([(x, y)])
			dict1[oldcord] = set1
		elif (x, y) in dict1[oldcord]:
			time += 1
		else:
			time += 5
			dict1[oldcord].add((x, y))
		if not (x, y) in dict1:
			dict1[x, y] = set([oldcord])
		else:
			dict1[x, y].add(oldcord)
	print(time)


N = (1, 0)
S = (-1, 0)
W = (0, -1)
E = (0, 1)

def addTuples(T1, T2):
	return tuple(map(lambda i, j: i + j, T1, T2))
T = int(input())
for t in range(T):
	moves = input()
	curr = (0, 0)
	HashMap = {curr: set({})}
	ans = 0
	for move in moves:
		next = None
		if move == 'N':
			next = addTuples(curr, N)
		elif move == 'W':
			next = addTuples(curr, W)
		elif move == 'S':
			next = addTuples(curr, S)
		else:
			next = addTuples(curr, E)
		if next not in HashMap:
			HashMap[next] = set({})
		if next not in HashMap[curr]:
			HashMap[next].add(curr)
			HashMap[curr].add(next)
			ans += 5
		else:
			ans += 1
		curr = next
	print(ans)


def reverse(char):
	if char == 'N':
		return 'S'
	if char == 'S':
		return 'N'
	if char == 'E':
		return 'W'
	if char == 'W':
		return 'E'

def alternate(start_x, start_y, char):
	if char == 'N':
		return (start_x, start_y + 1)
	if char == 'S':
		return (start_x, start_y - 1)
	if char == 'E':
		return (start_x + 1, start_y)
	if char == 'W':
		return (start_x - 1, start_y)

def solve(s):
	visited = {}
	start_x = 0
	start_y = 0
	result = 0
	for char in s:
		if (start_x, start_y) in visited and char in visited[start_x, start_y]:
			result += 1
		else:
			result += 5
		if not (start_x, start_y) in visited:
			visited[start_x, start_y] = set()
		visited[start_x, start_y].add(char)
		alt = alternate(start_x, start_y, char)
		if not alt in visited:
			visited[alt] = set()
		visited[alt].add(reverse(char))
		if char == 'N':
			start_y += 1
		elif char == 'S':
			start_y -= 1
		elif char == 'E':
			start_x += 1
		elif char == 'W':
			start_x -= 1
	return result
for i in range(int(input())):
	s = input()
	print(solve(s))


from collections import namedtuple
Delta = namedtuple('Delta', ['x', 'y'])
deltas = {'N': Delta(0, 1), 'S': Delta(0, -1), 'W': Delta(-1, 0), 'E': Delta(1, 0)}
tc = int(input())
while tc > 0:
	traces = set()
	(x1, y1) = (0, 0)
	finish_time = 0
	for direction in input():
		delta = deltas.get(direction)
		(x2, y2) = (x1 + delta.x, y1 + delta.y)
		if (x1, y1, x2, y2) in traces or (x2, y2, x1, y1) in traces:
			finish_time += 1
		else:
			finish_time += 5
			traces.add((x2, y2, x1, y1))
		(x1, y1) = (x2, y2)
	print(finish_time)
	tc -= 1


dic = {'N': [0, 1], 'S': [0, -1], 'E': [1, 0], 'W': [-1, 0]}
for _ in range(int(input())):
	ans = 0
	s = set()
	(x, y) = (0, 0)
	s.add((0, 0))
	for c in input():
		(dx, dy) = dic[c]
		m = (x + dx, y + dy)
		if m in s:
			ans += 1
		else:
			ans += 5
		x += dx * 2
		y += dy * 2
		s.add(m)
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	s = input()
	dc = defaultdict(tuple)
	x = [0, 0]
	dc[0, 0] = 0
	c = 0
	for i in s:
		p = tuple(x)
		if i == 'N':
			x[1] += 1
		elif i == 'S':
			x[1] -= 1
		elif i == 'E':
			x[0] += 1
		else:
			x[0] -= 1
		if dc[p + tuple(x)] == 1 or dc[tuple(x) + p] == 1:
			c += 1
		else:
			c += 5
			dc[p + tuple(x)] = 1
	print(c)


T = int(input())
for _ in range(T):
	strx = input()
	vis = {}
	ans = 0
	(x, y) = (0, 0)
	for z in strx:
		if z == 'S':
			(nx, ny) = (x + 1, y)
		elif z == 'N':
			(nx, ny) = (x - 1, y)
		elif z == 'W':
			(nx, ny) = (x, y - 1)
		else:
			(nx, ny) = (x, y + 1)
		(t1, t2) = ((x, y), (nx, ny))
		if t1 > t2:
			k = t1
			t1 = t2
			t2 = k
		if (t1, t2) in vis:
			ans += 1
		else:
			ans += 5
		(x, y) = (nx, ny)
		vis[t1, t2] = 1
	print(ans)


for t in range(int(input())):
	directions = input()
	sec = 0
	arr = {}
	i = j = 0
	for k in range(len(directions)):
		first = str(i * 10 ** 5 + j)
		if directions[k] == 'N':
			i += 1
		if directions[k] == 'S':
			i -= 1
		if directions[k] == 'E':
			j += 1
		if directions[k] == 'W':
			j -= 1
		last = str(i * 10 ** 5 + j)
		if first + ',' + last in arr or last + ',' + first in arr:
			sec += 1
		else:
			sec += 5
		arr[first + ',' + last] = 1
	print(sec)


for _ in range(int(input())):
	strin = input()
	(x, y) = (0, 0)
	tot = 0
	(ini_x, ini_y) = (0, 0)
	path = set()
	for i in strin:
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'W':
			x -= 1
		elif i == 'E':
			x += 1
		if (x, y, ini_x, ini_y) in path:
			tot += 1
		else:
			path.add((x, y, ini_x, ini_y))
			path.add((ini_x, ini_y, x, y))
			tot += 5
		ini_y = y
		ini_x = x
	print(tot)


t = int(input())
while t:
	t -= 1
	tot = 0
	str = input()
	mp = {'N': (0, 1), 'E': (1, 0), 'S': (0, -1), 'W': (-1, 0)}
	loc = [0, 0]
	st = set()
	for char in str:
		dir = mp[char]
		oldloc = (loc[0], loc[1])
		loc[0] += dir[0]
		loc[1] += dir[1]
		newloc = (loc[0], loc[1])
		if (oldloc, newloc) not in st:
			tot += 5
		else:
			tot += 1
		st.add((oldloc, newloc))
		st.add((newloc, oldloc))
	print(tot)


def solve_case():
	s = input()
	n = len(s)
	dur = 0
	(x, y) = (0, 0)
	segs = set()
	for i in range(n):
		(nx, ny) = (x, y)
		nx += int(s[i] == 'E') - int(s[i] == 'W')
		ny += int(s[i] == 'N') - int(s[i] == 'S')
		st = (x, y)
		en = (nx, ny)
		if (st, en) in segs or (en, st) in segs:
			dur += 1
		else:
			dur += 5
			segs.add((st, en))
		(x, y) = (nx, ny)
	print(dur)
t = int(input())
for _ in range(t):
	solve_case()


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)


def process_test_case(i_test):
	path = input()
	bound = len(path)
	path_dict = {}
	n_sec = 0
	i = bound
	j = bound
	for c in path:
		if c == 'N':
			i_path = str(i) + str(i) + str(j) + str(j + 1)
			j += 1
		if c == 'S':
			i_path = str(i) + str(i) + str(j - 1) + str(j)
			j -= 1
		if c == 'E':
			i_path = str(i) + str(i + 1) + str(j) + str(j)
			i += 1
		if c == 'W':
			i_path = str(i - 1) + str(i) + str(j) + str(j)
			i -= 1
		if i_path in path_dict:
			n_sec += 1
		else:
			n_sec += 5
		path_dict[i_path] = True
	print(n_sec)
	return None
n_tests = int(input())
for i_test in range(1, n_tests + 1):
	process_test_case(i_test)


for i in range(int(input())):
	k = list(input())
	l = (0, 0)
	(j, s) = (0, 0)
	y = set()
	while j < len(k):
		if k[j] == 'N':
			x = (l[0] + 1, l[1])
		elif k[j] == 'S':
			x = (l[0] - 1, l[1])
		elif k[j] == 'W':
			x = (l[0], l[1] + 1)
		else:
			x = (l[0], l[1] - 1)
		if l + x not in y:
			s = s + 5
			y.add(l + x)
			y.add(x + l)
		else:
			s = s + 1
		l = x
		j = j + 1
	print(s)


cases = int(input())
times = []
for i in range(cases):
	path = {(0, 0, 0)}
	time = 0
	(X, Y) = (0, 0)
	paths = input()
	for i in paths:
		if i == 'N':
			if (X, Y, 'N') in path or (X, Y + 1, 'S') in path:
				time += 1
			else:
				time += 5
				path.add((X, Y, 'N'))
			Y += 1
		elif i == 'S':
			if (X, Y, 'S') in path or (X, Y - 1, 'N') in path:
				time += 1
			else:
				time += 5
				path.add((X, Y, i))
			Y -= 1
		elif i == 'E':
			if (X, Y, i) in path or (X + 1, Y, 'W') in path:
				time += 1
			else:
				time += 5
				path.add((X, Y, i))
			X += 1
		else:
			if (X, Y, i) in path or (X - 1, Y, 'E') in path:
				time += 1
			else:
				time += 5
				path.add((X, Y, i))
			X -= 1
	times.append(time)
for i in times:
	print(i)


from collections import defaultdict
for _ in range(int(input())):
	s = input()
	x = 0
	y = 0
	a = 0
	b = 0
	d = defaultdict(list)
	count = 0
	for i in range(len(s)):
		if s[i] == 'N':
			a = x
			b = y + 1
		elif s[i] == 'S':
			a = x
			b = y - 1
		elif s[i] == 'W':
			a = x - 1
			b = y
		elif s[i] == 'E':
			a = x + 1
			b = y
		if (a, b) in d[x, y]:
			count += 1
		else:
			d[x, y].append((a, b))
			d[a, b].append((x, y))
			count += 5
		x = a
		y = b
	print(count)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
for _ in range(int(input())):
	x = 0
	y = 0
	s = input()
	z = dict()
	z[x, y] = set()
	su = 0
	for i in range(len(s)):
		f = (x, y)
		if s[i] == 'N':
			y += 1
		elif s[i] == 'S':
			y -= 1
		elif s[i] == 'E':
			x += 1
		else:
			x -= 1
		if (x, y) in z[f]:
			su += 1
		elif (x, y) in z and f in z[x, y]:
			su += 1
		else:
			su += 5
		z[f].add((x, y))
		if (x, y) in z:
			z[x, y].add(f)
		else:
			z[x, y] = set()
			z[x, y].add(f)
	print(su)


for _ in range(int(input())):
	dirs = input().strip()
	vs = set()
	(x, y) = (0, 0)
	t = 0
	for dir in dirs:
		if dir == 'N':
			(xx, yy) = (x + 1, y)
		elif dir == 'S':
			(xx, yy) = (x - 1, y)
		elif dir == 'W':
			(xx, yy) = (x, y - 1)
		else:
			(xx, yy) = (x, y + 1)
		if ((x, y), (xx, yy)) in vs or ((xx, yy), (x, y)) in vs:
			t += 1
		else:
			t += 5
			vs.add(((x, y), (xx, yy)))
		(x, y) = (xx, yy)
	print(t)


def test():
	string = input()
	visited = set()
	(i, j) = (0, 0)
	d = {'S': (0, -1), 'N': (0, 1), 'W': (-1, 0), 'E': (1, 0)}
	sum_ = 0
	for s in string:
		next_i = i + d[s][0]
		next_j = j + d[s][1]
		sum_ += 1 if (i, j, next_i, next_j) in visited else 5
		visited.add((i, j, next_i, next_j))
		visited.add((next_i, next_j, i, j))
		i = next_i
		j = next_j
	print(sum_)
n = int(input())
for _ in range(n):
	test()


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	dc = defaultdict(int)
	res = 0
	xx = 0
	yy = 0
	arr = []
	for x in s:
		if x == 'N':
			if (xx, yy + 1 / 2) in dc:
				res += 1
			else:
				dc[xx, yy + 1 / 2] = 1
				res += 5
			yy += 1
		if x == 'S':
			if (xx, yy - 1 / 2) in dc:
				res += 1
			else:
				dc[xx, yy - 1 / 2] = 1
				res += 5
			yy -= 1
		if x == 'E':
			if (xx + 1 / 2, yy) in dc:
				res += 1
			else:
				dc[xx + 1 / 2, yy] = 1
				res += 5
			xx += 1
		if x == 'W':
			if (xx - 1 / 2, yy) in dc:
				res += 1
			else:
				dc[xx - 1 / 2, yy] = 1
				res += 5
			xx -= 1
	print(res)


def skier(s):
	x = 0
	y = 0
	v = set()
	ans = 0
	for i in s:
		(px, py) = (x, y)
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		else:
			x -= 1
		if ((px, py), (x, y)) in v or ((x, y), (px, py)) in v:
			ans += 1
		else:
			ans += 5
			v.add(((px, py), (x, y)))
			v.add(((x, y), (px, py)))
	return ans
t = int(input())
for _ in range(t):
	print(skier(input()))


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

def solve(path):
	(visited, begin, time) = (set(), [0, 0], 0)
	for p in path:
		nxt = direct[p]
		interim = (begin[0] + nxt[0], begin[1] + nxt[1])
		interim2 = tuple(begin)
		p1 = min(interim, interim2)
		p2 = max(interim, interim2)
		edge = (p2[0], p2[1], p1[0], p1[1])
		if edge not in visited:
			time += 5
			visited.add(edge)
		else:
			time += 1
		begin[0] += nxt[0]
		begin[1] += nxt[1]
	print(time)
for _ in range(int(input())):
	solve(input())


t = int(input())
for i in range(t):
	s = input()
	d = {}
	x = 0
	y = 0
	c = 0
	rc = 0
	for j in s:
		m = x
		n = y
		if j == 'N':
			y += 1
		elif j == 'S':
			y -= 1
		elif j == 'E':
			x += 1
		else:
			x -= 1
		if (x, y, m, n) in d or (m, n, x, y) in d:
			rc += 1
		else:
			c += 1
			d[m, n, x, y] = 1
	print(c * 5 + rc)


n = int(input())
for i in range(n):
	s = input()
	k = 0
	(x, y) = (0, 0)
	A = set()
	for j in range(len(s)):
		(x1, y1) = (x, y)
		if s[j] == 'N':
			y += 1
		elif s[j] == 'S':
			y -= 1
		elif s[j] == 'E':
			x += 1
		else:
			x -= 1
		if (x1, y1, x, y) in A or (x, y, x1, y1) in A:
			k += 1
		else:
			A.add((x, y, x1, y1))
			k += 5
	print(k)


t = int(input())
for _ in range(t):
	s = input()
	init = [0, 0]
	visited = set()
	ans = 0
	for i in s:
		ini = init[:]
		if i == 'N':
			init[0] += 1
		elif i == 'S':
			init[0] -= 1
		elif i == 'E':
			init[1] += 1
		else:
			init[1] -= 1
		if tuple(ini + init) in visited or tuple(init + ini) in visited:
			ans += 1
		else:
			visited.add(tuple(ini + init))
			ans += 5
	print(ans)


for t in range(int(input())):
	dic = {}
	x = y = 0
	time = 0
	for c in input().rstrip('\n'):
		p = x
		q = y
		if c == 'N':
			y += 1
		elif c == 'S':
			y -= 1
		elif c == 'W':
			x -= 1
		elif c == 'E':
			x += 1
		if (x, y, p, q) in dic or (p, q, x, y) in dic:
			time += 1
		else:
			time += 5
		dic[p, q, x, y] = 1
	print(time)


def direction_change(lst, i):
	if i == 'N':
		lst[0] += 1
	elif i == 'S':
		lst[0] -= 1
	elif i == 'W':
		lst[1] += 1
	else:
		lst[1] -= 1
	return (lst[0], lst[1])
for k in range(int(input())):
	ans = 0
	st = set()
	(x, y) = (0, 0)
	s = input()
	for i in s:
		x1 = x
		y1 = y
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'W':
			x += 1
		else:
			x -= 1
		if (x, y, x1, y1) in st or (x1, y1, x, y) in st:
			ans += 1
		else:
			ans += 5
			st.add((x1, y1, x, y))
	print(ans)


inp = {'N': (1, 0), 'S': (-1, 0), 'E': (0, 1), 'W': (0, -1)}
for _ in range(int(input())):
	d = {}
	i = input()
	(x, y, s) = (0, 0, 0)
	for j in i:
		nx = x + inp[j][0]
		ny = y + inp[j][1]
		s += min(d.get((x, y, nx, ny), 5), d.get((nx, ny, x, y), 5))
		d[nx, ny, x, y] = 1
		x = nx
		y = ny
	print(s)


t = int(input())
for _ in range(t):
	s = str(input())
	n = len(s)
	x = 0
	y = 0
	S = set()
	ans = 0
	for i in range(n):
		(nx, ny) = (x, y)
		if s[i] == 'N':
			ny += 1
		elif s[i] == 'S':
			ny -= 1
		elif s[i] == 'E':
			nx += 1
		else:
			nx -= 1
		if ((x, y), (nx, ny)) not in S:
			ans += 5
		else:
			ans += 1
		S.add(((x, y), (nx, ny)))
		S.add(((nx, ny), (x, y)))
		(x, y) = (nx, ny)
	print(ans)


test_cases = int(input().strip())
directions = ['N', 'S', 'E', 'W']
total_time = []
for _ in range(test_cases):
	full_path = set()
	prev = (0, 0)
	time = 0
	path = input()
	for direc in path:
		if direc == 'N':
			curr = (prev[0], prev[1] + 1)
		elif direc == 'S':
			curr = (prev[0], prev[1] - 1)
		elif direc == 'E':
			curr = (prev[0] + 1, prev[1])
		else:
			curr = (prev[0] - 1, prev[1])
		if curr + prev in full_path:
			time += 1
		else:
			time += 5
		full_path.add(curr + prev)
		full_path.add(prev + curr)
		prev = curr
	total_time.append(time)
print(*total_time, sep='\n')


from sys import stdin, stdout
import math
import heapq
t = 1

def aint():
	return int(input().strip())

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

def fint():
	return list(map(int, stdin.readline().split()))

def main():
	(x1, y1) = (0, 0)
	s = input()
	st = set()
	ans = 0
	for i in s:
		x2 = x1
		y2 = y1
		if i == 'N':
			y2 += 1
		elif i == 'S':
			y2 -= 1
		elif i == 'E':
			x2 += 1
		else:
			x2 -= 1
		if (x1, y1, x2, y2) in st or (x2, y2, x1, y1) in st:
			ans += 1
		else:
			ans += 5
			st.add((x1, y1, x2, y2))
		x1 = x2
		y1 = y2
	print(ans)
	return
t = int(input())
for i in range(t):
	main()


t = int(input())
for _ in range(t):
	s = input()
	paths = set()
	time = 0
	loc = [0, 0]
	for i in s:
		if i == 'N':
			delta = [1, 0]
		elif i == 'S':
			delta = [-1, 0]
		elif i == 'W':
			delta = [0, 1]
		else:
			delta = [0, -1]
		p1 = f'{loc[0]},{loc[1]},{loc[0] + delta[0]},{loc[1] + delta[1]}'
		p2 = f'{loc[0] + delta[0]},{loc[1] + delta[1]},{loc[0]},{loc[1]}'
		loc = [loc[0] + delta[0], loc[1] + delta[1]]
		if p1 in paths or p2 in paths:
			time += 1
		else:
			paths.add(p1)
			paths.add(p2)
			time += 5
	print(time)


t = int(input())
for i in range(t):
	c = 0
	n = list(input())
	v = {}
	x = y = 0
	for h in range(len(n)):
		if n[h] == 'N':
			s = str(x) + ',' + str(y) + ',' + str(x) + ',' + str(y + 1)
			s1 = str(x) + ',' + str(y + 1) + ',' + str(x) + ',' + str(y)
			if s in v or s1 in v:
				c += 1
			else:
				c += 5
				v[str(x) + ',' + str(y) + ',' + str(x) + ',' + str(y + 1)] = 42
			y += 1
		elif n[h] == 'S':
			s = str(x) + ',' + str(y) + ',' + str(x) + ',' + str(y - 1)
			s1 = str(x) + ',' + str(y - 1) + ',' + str(x) + ',' + str(y)
			if s in v or s1 in v:
				c += 1
			else:
				c += 5
				v[str(x) + ',' + str(y) + ',' + str(x) + ',' + str(y - 1)] = 42
			y -= 1
		elif n[h] == 'W':
			s = str(x) + ',' + str(y) + ',' + str(x - 1) + ',' + str(y)
			s1 = str(x - 1) + ',' + str(y) + ',' + str(x) + ',' + str(y)
			if s in v or s1 in v:
				c += 1
			else:
				c += 5
				v[str(x) + ',' + str(y) + ',' + str(x - 1) + ',' + str(y)] = 42
			x -= 1
		elif n[h] == 'E':
			s = str(x) + ',' + str(y) + ',' + str(x + 1) + ',' + str(y)
			s1 = str(x + 1) + ',' + str(y) + ',' + str(x) + ',' + str(y)
			if s in v or s1 in v:
				c += 1
			else:
				c += 5
				v[str(x) + ',' + str(y) + ',' + str(x + 1) + ',' + str(y)] = 42
			x += 1
	print(c)


def f(l, d):
	if d == 'N':
		return (l[0], l[1] + 1)
	elif d == 'S':
		return (l[0], l[1] - 1)
	elif d == 'E':
		return (l[0] + 1, l[1])
	else:
		return (l[0] - 1, l[1])
for _ in range(int(input())):
	s = input()
	visited = set()
	ans = 0
	parent = (0, 0)
	for i in s:
		curr = f(parent, i)
		if (parent[0], parent[1], curr[0], curr[1]) in visited or (curr[0], curr[1], parent[0], parent[1]) in visited:
			ans += 1
		else:
			ans += 5
		visited.add((parent[0], parent[1], curr[0], curr[1]))
		parent = curr
	print(ans)


from math import *
t = int(input())
for _ in range(t):
	s = input()
	pos = (0, 0)
	visited = set()
	time = 0
	for i in range(len(s)):
		if s[i] == 'E':
			(x, y) = pos
			prev = pos
			pos = (x + 1, y)
			if (pos, prev) in visited or (prev, pos) in visited:
				time += 1
			else:
				time += 5
				visited.add((prev, pos))
		elif s[i] == 'W':
			(x, y) = pos
			prev = pos
			pos = (x - 1, y)
			if (pos, prev) in visited or (prev, pos) in visited:
				time += 1
			else:
				time += 5
				visited.add((prev, pos))
		elif s[i] == 'N':
			(x, y) = pos
			prev = pos
			pos = (x, y + 1)
			if (pos, prev) in visited or (prev, pos) in visited:
				time += 1
			else:
				time += 5
				visited.add((prev, pos))
		elif s[i] == 'S':
			(x, y) = pos
			prev = pos
			pos = (x, y - 1)
			if (pos, prev) in visited or (prev, pos) in visited:
				time += 1
			else:
				time += 5
				visited.add((prev, pos))
	print(time)


def main():
	string = input()
	horizontal = {}
	x = 0
	y = 0
	ans = 0
	for i in range(len(string)):
		if string[i] == 'N':
			if horizontal.get((x, y, x, y + 1)) == None:
				ans += 5
				horizontal[x, y, x, y + 1] = 1
				horizontal[x, y + 1, x, y] = 1
			else:
				ans += 1
			y = y + 1
		elif string[i] == 'S':
			if horizontal.get((x, y, x, y - 1)) == None:
				ans += 5
				horizontal[x, y, x, y - 1] = 1
				horizontal[x, y - 1, x, y] = 1
			else:
				ans += 1
			y -= 1
		elif string[i] == 'E':
			if horizontal.get((x, y, x + 1, y)) == None:
				ans += 5
				horizontal[x, y, x + 1, y] = 1
				horizontal[x + 1, y, x, y] = 1
			else:
				ans += 1
			x += 1
		else:
			if horizontal.get((x, y, x - 1, y)) == None:
				ans += 5
				horizontal[x, y, x - 1, y] = 1
				horizontal[x - 1, y, x, y] = 1
			else:
				ans += 1
			x -= 1
	print(ans)
t = int(input())
while t:
	main()
	t -= 1


t = int(input())
while t:
	t -= 1
	dir = input()
	visited = {}
	cost = 0
	x = 0
	y = 0
	for i in range(len(dir)):
		path = str(x) + str(y)
		if dir[i] == 'N':
			y += 1
		elif dir[i] == 'S':
			y -= 1
		elif dir[i] == 'E':
			x += 1
		else:
			x -= 1
		nxt_path = str(x) + str(y)
		flag1 = False
		flag2 = False
		try:
			if visited[path + nxt_path]:
				cost += 1
		except:
			flag1 = True
		try:
			if visited[nxt_path + path] and flag1:
				cost += 1
		except:
			flag2 = True
		if flag2 and flag1:
			visited[path + nxt_path] = 1
			cost += 5
	print(cost)


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)


def update(dir, curr):
	curr = list(curr)
	if dir == 'N':
		curr[1] = curr[1] + 1
	elif dir == 'S':
		curr[1] = curr[1] - 1
	elif dir == 'E':
		curr[0] = curr[0] + 1
	else:
		curr[0] = curr[0] - 1
	return tuple(curr)
t = int(input())
hashset = set()
for i in range(0, t):
	path = input().strip()
	cost = 0
	curr = (0, 0)
	for dir in path:
		new_curr = update(dir, curr)
		if (curr, new_curr) in hashset or (new_curr, curr) in hashset:
			cost += 1
		else:
			cost += 5
			hashset.add((curr, new_curr))
		curr = new_curr
	hashset.clear()
	print(cost)


from collections import defaultdict
t = int(input())
while t:
	s = input()
	(x, y) = (0, 0)
	d = defaultdict(int)
	ans = 0
	d[0, 0, 0, 0] = 1
	(inx, iny) = (0, 0)
	for i in s:
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		elif i == 'W':
			x -= 1
		if d[inx, iny, x, y] == 0:
			ans += 5
			d[inx, iny, x, y] += 1
			d[x, y, inx, iny] += 1
		else:
			ans += 1
		inx = x
		iny = y
	print(ans)
	t -= 1


def move(p, c):
	if c == 'N':
		return (p[0], p[1] + 1)
	if c == 'S':
		return (p[0], p[1] - 1)
	if c == 'W':
		return (p[0] - 1, p[1])
	if c == 'E':
		return (p[0] + 1, p[1])
t = int(input())
for i in range(t):
	s = input()
	ans = 0
	routes = set()
	p = (0, 0)
	routes.add(p)
	for c in s:
		pp = move(p, c)
		route = (p[0], p[1], pp[0], pp[1])
		reverse = (pp[0], pp[1], p[0], p[1])
		if route in routes:
			ans += 1
		else:
			routes.add(route)
			routes.add(reverse)
			ans += 5
		p = pp
	print(ans)


def solve(string):
	(x, y) = (0, 0)
	(x1, y1) = (0, 0)
	s = set()
	count = 0
	for i in string:
		if i == 'N':
			y1 = y + 1
		elif i == 'S':
			y1 = y - 1
		elif i == 'W':
			x1 = x - 1
		elif i == 'E':
			x1 = x + 1
		if (x, y, x1, y1) in s or (x1, y1, x, y) in s:
			count += 1
		else:
			count += 5
			s.add((x, y, x1, y1))
		(x, y) = (x1, y1)
	return count
t = int(input())
for _ in range(t):
	string = input()
	print(solve(string))


t = int(input())
AnsList = []
for _ in range(t):
	s = input()
	Ans = 0
	pathList = {}
	(x1, x2, y1, y2) = (0, 0, 0, 0)
	for i in range(len(s)):
		d = s[i]
		if d == 'N':
			y2 = y1 + 1
		elif d == 'S':
			y2 = y1 - 1
		elif d == 'E':
			x2 = x1 + 1
		else:
			x2 = x1 - 1
		pf = str(x1) + str(y1) + str(x2) + str(y2)
		pr = str(x2) + str(y2) + str(x1) + str(y1)
		if pf in pathList:
			Ans += 1
		else:
			Ans += 5
			pathList[pf] = 1
			pathList[pr] = 1
		(x1, y1) = (x2, y2)
	AnsList.append(Ans)
for x in AnsList:
	print(x)


import math

def tc():
	s = input()
	vis = set()
	(x, y) = (0, 0)
	time = 0
	for d in s:
		(dx, dy) = (0, 0)
		if d == 'N':
			dy = 0.5
			y += 1
		elif d == 'S':
			dy = -0.5
			y -= 1
		elif d == 'E':
			dx += 0.5
			x += 1
		else:
			dx -= 0.5
			x -= 1
		mid = (x - dx, y - dy)
		if mid in vis:
			time += 1
		else:
			vis.add(mid)
			time += 5
	return time
T = int(input())
for _ in range(T):
	ans = tc()
	print(ans)


from collections import defaultdict as dd
t = int(input())
while t:
	d = dd(int)
	s = input()
	x = 0
	y = 0
	d[x, y] = 1
	ans = 0
	px = 0
	py = 0
	for i in range(len(s)):
		a = s[i]
		if a == 'N':
			y += 1
			l = [(px, py), (x, y)]
			l.sort()
			l = tuple(l)
			if d[l]:
				ans += 1
			else:
				ans += 5
		elif a == 'S':
			y -= 1
			l = [(px, py), (x, y)]
			l.sort()
			l = tuple(l)
			if d[l]:
				ans += 1
			else:
				ans += 5
		elif a == 'E':
			x += 1
			l = [(px, py), (x, y)]
			l.sort()
			l = tuple(l)
			if d[l]:
				ans += 1
			else:
				ans += 5
		elif a == 'W':
			x -= 1
			l = [(px, py), (x, y)]
			l.sort()
			l = tuple(l)
			if d[l]:
				ans += 1
			else:
				ans += 5
		d[l] = 1
		px = x
		py = y
	print(ans)
	t -= 1


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def mex(li):
	check = [0] * 1001
	for i in li:
		check[i] += 1
	for i in range(len(check)):
		if check[i] == 0:
			return i
from math import *
for _ in range(int(input())):
	string = input()
	done = set()
	(x, y, time) = (0, 0, 0)
	(x1, y1) = (0, 0)
	for i in string:
		if i == 'E':
			x1 = x + 1
		elif i == 'W':
			x1 = x - 1
		elif i == 'S':
			y1 = y - 1
		elif i == 'N':
			y1 = y + 1
		if (x, y, x1, y1) in done:
			time += 1
		elif (x1, y1, x, y) in done:
			time += 1
		else:
			time += 5
			done.add((x, y, x1, y1))
		(x, y) = (x1, y1)
	print(time)


t = int(input())
for _ in range(t):
	s = input()
	x = 0
	y = 0
	ans = 0
	set1 = set()
	for i in range(len(s)):
		p = x
		q = y
		if s[i] == 'E':
			x += 1
		elif s[i] == 'W':
			x -= 1
		elif s[i] == 'N':
			y += 1
		else:
			y -= 1
		if (p, q, x, y) in set1 or (x, y, p, q) in set1:
			ans += 1
		else:
			ans += 5
			set1.add((p, q, x, y))
	print(ans)


import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
import heapq as h, time
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def getInt():
	return int(input())

def getStrs():
	return input().split()

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

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def getBin():
	return list(map(int, list(input())))

def isInt(s):
	return '0' <= s[0] <= '9'

def ceil_(a, b):
	return a // b + (a % b > 0)
MOD = 10 ** 9 + 7

def solve():
	S = getStr()
	curr = [0, 0]
	used = set()
	ans = 0
	for i in range(len(S)):
		prev = curr[:]
		if S[i] == 'N':
			curr[1] += 1
		elif S[i] == 'S':
			curr[1] -= 1
		elif S[i] == 'E':
			curr[0] += 1
		else:
			curr[0] -= 1
		if tuple(prev + curr) in used:
			ans += 1
		else:
			ans += 5
			used.add(tuple(prev + curr))
			used.add(tuple(curr + prev))
	return ans
for _ in range(getInt()):
	print(solve())


for _ in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	d = {}
	c = 0
	for i in range(len(s)):
		x1 = x
		y1 = y
		if s[i] == 'S':
			y -= 1
		elif s[i] == 'N':
			y += 1
		elif s[i] == 'W':
			x -= 1
		else:
			x += 1
		if (x, y, x1, y1) in d or (x1, y1, x, y) in d:
			c += 1
		else:
			c += 5
			d[x1, y1, x, y] = 1
	print(c)


t = int(input())
for _ in range(t):
	s = input()
	c = [(0, 0)]
	x = 0
	y = 0
	z = 0
	for i in range(len(s)):
		if s[i] == 'N':
			y += 1
		if s[i] == 'S':
			y -= 1
		if s[i] == 'E':
			x += 1
		if s[i] == 'W':
			x -= 1
		c.append((x, y))
	p = set()
	for i in range(len(c) - 1):
		(p1, p2) = sorted((c[i], c[i + 1]))
		if (p1, p2) in p:
			z += 1
		else:
			z += 5
			p.add((p1, p2))
	print(z)


t = int(input())
for i in range(t):
	s = input()
	d = {}
	x = 0
	y = 0
	ans = 0
	for j in range(len(s)):
		x1 = x
		y1 = y
		if s[j] == 'N':
			y += 1
		elif s[j] == 'S':
			y -= 1
		elif s[j] == 'W':
			x -= 1
		else:
			x += 1
		if (x1, y1, x, y) in d or (x, y, x1, y1) in d:
			ans += 1
		else:
			ans += 5
			d[x1, y1, x, y] = 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import math

def inputIntArray():
	return list(map(int, input().rstrip().split()))

def inputArray():
	return input().rstrip().split()

def inputVars():
	return map(int, input().rstrip().split())

def inputNum():
	return int(input())

def main():
	for _ in range(inputNum()):
		directions = input()
		visited = {(0, 0): 1}
		(presRow, presCol) = (0, 0)
		time = 0
		for movement in directions:
			(p, q) = (presRow, presCol)
			if movement == 'N':
				presRow += 1
			elif movement == 'S':
				presRow -= 1
			elif movement == 'E':
				presCol += 1
			else:
				presCol -= 1
			if (presRow + p, presCol + q) in visited:
				time += 1
			else:
				time += 5
				visited[presRow + p, presCol + q] = 1
		print(time)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	p = input()
	s = complex(0, 0)
	ans = 0
	d = {'N': 1j, 'S': -1j, 'W': -1, 'E': 1}
	e = {0: []}
	for x in p:
		e[s + d[x]] = e.get(s + d[x], [])
		if s in e[s + d[x]]:
			ans += 1
		else:
			ans += 5
			e[s].append(s + d[x])
			e[s + d[x]].append(s)
		s += d[x]
	print(ans)


import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	s = input()
	oo = [0, 0]
	arr = list(s)
	d = set()
	ans = 0
	for k in arr:
		arr2 = oo.copy()
		if k == 'N':
			oo[1] += 1
		elif k == 'E':
			oo[0] += 1
		elif k == 'W':
			oo[0] -= 1
		else:
			oo[1] -= 1
		if (tuple(oo), tuple(arr2)) in d or (tuple(arr2), tuple(oo)) in d:
			ans += 1
		else:
			ans += 5
			d.add((tuple(arr2), tuple(oo)))
	print(ans)


for _ in range(int(input())):
	route = input()
	(x, y) = (0, 0)
	done = set()
	secs = 0
	for i in route:
		if i == 'E':
			nx = x + 1
			ny = y + 0
		if i == 'W':
			nx = x - 1
			ny = y + 0
		if i == 'N':
			nx = x + 0
			ny = y + 1
		if i == 'S':
			nx = x + 0
			ny = y - 1
		a = (nx, ny, x, y)
		b = (x, y, nx, ny)
		if a in done or b in done:
			secs += 1
		else:
			secs += 5
		done.add(a)
		done.add(b)
		(x, y) = (nx, ny)
	print(secs)


t = int(input())
for _ in range(t):
	s = input()
	dic = {}
	x = 0
	y = 0
	ans = 0
	for i in s:
		currx = x
		curry = y
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'E':
			x += 1
		else:
			x -= 1
		path = ((min(currx, x), min(curry, y)), (max(currx, x), max(curry, y)))
		if path in dic:
			ans += 1
		else:
			ans += 5
			dic[path] = 1
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	(x1, y1) = (0, 0)
	(x2, y2) = (0, 0)
	been = set()
	z = True
	ans = 0
	for i in s:
		if i == 'N':
			y2 -= 1
		elif i == 'S':
			y2 += 1
		elif i == 'W':
			x2 -= 1
		elif i == 'E':
			x2 += 1
		if z:
			z = False
			been.add((x1, y1, x2, y2))
			been.add((x2, y2, x1, y1))
			ans += 5
		elif (x1, y1, x2, y2) in been or (x2, y2, x1, y1) in been:
			ans += 1
		else:
			ans += 5
			been.add((x1, y1, x2, y2))
			been.add((x2, y2, x1, y1))
		(x1, y1) = (x2, y2)
	print(ans)


T = int(input())
for _ in range(T):
	S = input()
	pos = (0, 0)
	visited = {(pos, pos)}
	ans = 0
	for c in S:
		if c == 'N':
			n = (pos[0] + 1, pos[1])
		elif c == 'S':
			n = (pos[0] - 1, pos[1])
		elif c == 'W':
			n = (pos[0], pos[1] + 1)
		else:
			n = (pos[0], pos[1] - 1)
		if (n, pos) in visited or (pos, n) in visited:
			ans += 1
		else:
			ans += 5
		visited.add((n, pos))
		visited.add((pos, n))
		pos = n
	print(ans)


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


import sys
from collections import defaultdict, deque
from math import sqrt, gcd, factorial

def input():
	return sys.stdin.buffer.readline()[:-1]

def solve():
	m = defaultdict(int)
	(x, y) = (0, 0)
	ans = 0
	s = input().strip()
	for e in s:
		(a, b) = (x, y)
		if e == ord('N'):
			y += 1
		elif e == ord('S'):
			y -= 1
		elif e == ord('E'):
			x += 1
		elif e == ord('W'):
			x -= 1
		l = [(x, y), (a, b)]
		l.sort()
		l = tuple(l)
		if m[l]:
			ans += 1
		else:
			ans += 5
			m[l] = 1
	print(ans)
t = 1
t = int(input())
for case in range(1, t + 1):
	ans = solve()


from collections import defaultdict
for i in range(int(input())):
	S = input()
	x = 0
	y = 0
	Ans = 0
	Dict = defaultdict(bool)
	for i in S:
		if i == 'N':
			if Dict[x, y, x, y + 1] or Dict[x, y + 1, x, y]:
				Ans += 1
			else:
				Ans += 5
				Dict[x, y, x, y + 1] = True
			y += 1
		elif i == 'S':
			if Dict[x, y, x, y - 1] or Dict[x, y - 1, x, y]:
				Ans += 1
			else:
				Ans += 5
				Dict[x, y, x, y - 1] = True
			y -= 1
		elif i == 'E':
			if Dict[x, y, x + 1, y] or Dict[x + 1, y, x, y]:
				Ans += 1
			else:
				Ans += 5
				Dict[x, y, x + 1, y] = True
			x += 1
		elif i == 'W':
			if Dict[x, y, x - 1, y] or Dict[x - 1, y, x, y]:
				Ans += 1
			else:
				Ans += 5
				Dict[x, y, x - 1, y] = True
			x -= 1
	print(Ans)


from sys import stdin
a = int(stdin.readline())
for b in range(0, a):
	startx = 0
	starty = 0
	A = set()
	B = stdin.readline()
	sum = 0
	for k in range(0, len(B) - 1):
		if B[k] == 'N':
			starty += 1
		if B[k] == 'S':
			starty -= 1
		if B[k] == 'E':
			startx += 1
		if B[k] == 'W':
			startx -= 1
		ll = len(A)
		if B[k] == 'N' or B[k] == 'S':
			if B[k] == 'N':
				A.add((1, startx, starty))
			elif B[k] == 'S':
				A.add((1, startx, starty + 1))
		elif B[k] == 'E' or B[k] == 'W':
			if B[k] == 'E':
				A.add((-1, startx, starty))
			elif B[k] == 'W':
				A.add((-1, startx + 1, starty))
		if len(A) != ll:
			sum += 5
		else:
			sum += 1
	print(sum)


t = int(input())
for i in range(t):
	s = input()
	path = set()
	start = (0, 0)
	ans = 0
	for c in s:
		if c == 'S':
			end = (start[0], start[1] - 1)
		elif c == 'N':
			end = (start[0], start[1] + 1)
		elif c == 'W':
			end = (start[0] - 1, start[1])
		else:
			end = (start[0] + 1, start[1])
		if (start, end) in path or (end, start) in path:
			ans += 1
		else:
			ans += 5
			path.add((start, end))
		start = end
	print(ans)


t = int(input())
for _ in range(t):
	s = input()
	st = {}
	n = len(s)
	(i, j) = (n, n)
	cost = 0
	for x in s:
		lt = []
		lt.extend([i, j])
		if x == 'N':
			i += 1
		elif x == 'S':
			i -= 1
		elif x == 'E':
			j += 1
		else:
			j -= 1
		lt1 = lt + [i] + [j]
		lt2 = [i] + [j] + lt
		lt1 = ''.join(map(str, lt1))
		lt2 = ''.join(map(str, lt2))
		if lt1 in st or lt2 in st:
			cost += 1
		else:
			cost += 5
			st[lt1] = 1
	print(cost)


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	x = y = 0
	Dict = defaultdict(int)
	cost = 0
	for i in s:
		if i == 'N':
			if Dict[x, y, x, y + 1] == 1:
				cost += 1
			else:
				cost += 5
			Dict[x, y, x, y + 1] = 1
			Dict[x, y + 1, x, y] = 1
			y += 1
		elif i == 'S':
			if Dict[x, y, x, y - 1] == 1:
				cost += 1
			else:
				cost += 5
			Dict[x, y, x, y - 1] = 1
			Dict[x, y - 1, x, y] = 1
			y -= 1
		elif i == 'E':
			if Dict[x, y, x + 1, y] == 1:
				cost += 1
			else:
				cost += 5
			Dict[x, y, x + 1, y] = 1
			Dict[x + 1, y, x, y] = 1
			x += 1
		elif i == 'W':
			if Dict[x, y, x - 1, y] == 1:
				cost += 1
			else:
				cost += 5
			Dict[x, y, x - 1, y] = 1
			Dict[x - 1, y, x, y] = 1
			x -= 1
	print(cost)


from sys import stdin

def main():
	readline = stdin.readline
	t = int(readline())
	res = []
	for _ in range(t):
		s = readline().strip()
		dNS = dict()
		dWE = dict()
		count = 0
		y = 0
		x = 0
		for c in s:
			if c == 'N':
				a = str(x) + '_' + str(y)
				y += 1
				b = str(x) + '_' + str(y)
				flag = 1
			elif c == 'S':
				b = str(x) + '_' + str(y)
				y -= 1
				a = str(x) + '_' + str(y)
				flag = 1
			elif c == 'W':
				b = str(x) + '_' + str(y)
				x -= 1
				a = str(x) + '_' + str(y)
				flag = 0
			elif c == 'E':
				a = str(x) + '_' + str(y)
				x += 1
				b = str(x) + '_' + str(y)
				flag = 0
			c = a + '_' + b
			if flag == 1:
				if c not in dNS:
					count += 5
					dNS[c] = 1
				else:
					count += 1
			elif c not in dWE:
				count += 5
				dWE[c] = 1
			else:
				count += 1
		res.append(count)
	for i in range(t):
		print(res[i])
main()


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)


for _ in range(int(input())):
	S = input()
	V = set()
	ans = 0
	(x, y) = (0, 0)
	for e in S:
		(nx, ny) = (x, y)
		if e == 'W':
			nx = x - 1
		elif e == 'E':
			nx = x + 1
		elif e == 'S':
			ny = y - 1
		else:
			ny = y + 1
		if (x, y, nx, ny) in V or (nx, ny, x, y) in V:
			ans += 1
		else:
			ans += 5
		V.add((x, y, nx, ny))
		(x, y) = (nx, ny)
	print(ans)


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


from collections import defaultdict as dd
for _ in range(int(input())):
	s1 = input()
	x = 0
	y = 0
	px = 0
	py = 0
	s = 0
	d = dd(int)
	for i in range(len(s1)):
		if s1[i] == 'N':
			y += 1
			g = [(x, y), (px, py)]
			g.sort()
			g = tuple(g)
			if d[g] == -1:
				s += 1
			else:
				s += 5
				d[g] = -1
		elif s1[i] == 'S':
			y -= 1
			g = [(x, y), (px, py)]
			g.sort()
			g = tuple(g)
			if d[g] == -1:
				s += 1
			else:
				s += 5
				d[g] = -1
		elif s1[i] == 'W':
			x -= 1
			g = [(x, y), (px, py)]
			g.sort()
			g = tuple(g)
			if d[g] == -1:
				s += 1
			else:
				s += 5
				d[g] = -1
		else:
			x += 1
			g = [(x, y), (px, py)]
			g.sort()
			g = tuple(g)
			if d[g] == -1:
				s += 1
			else:
				s += 5
				d[g] = -1
		px = x
		py = y
	print(s)


from collections import defaultdict

def solve(path):
	(x, y, count) = (0, 0, 0)
	ns_stored = defaultdict(lambda : defaultdict(lambda : False))
	ew_stored = defaultdict(lambda : defaultdict(lambda : False))
	for p in path:
		new_x = x + 1 if p == 'E' else x - 1 if p == 'W' else x
		new_y = y + 1 if p == 'N' else y - 1 if p == 'S' else y
		x_pos = (x + new_x) / 2
		y_pos = (y + new_y) / 2
		if p in 'NS':
			if ns_stored[x_pos][y_pos]:
				count += 1
			else:
				count += 5
				ns_stored[x_pos][y_pos] = True
		if p in 'EW':
			if ew_stored[x_pos][y_pos]:
				count += 1
			else:
				count += 5
				ew_stored[x_pos][y_pos] = True
		(x, y) = (new_x, new_y)
	return count
for _ in range(int(input())):
	path = input()
	print(solve(path))


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
for _ in range(int(cin())):
	s = cin()[:-1]
	d = {(0, 0): 1}
	x = y = ans = 0
	for i in range(len(s)):
		a = x
		b = y
		y += (s[i] == 'N') * 1 + (s[i] == 'S') * -1
		x += (s[i] == 'E') * 1 + (s[i] == 'W') * -1
		if (a + x, b + y) in d:
			ans += 1
		else:
			ans += 5
			d[a + x, b + y] = 1
	cout(str(ans) + '\n')


t = int(input())
while t > 0:
	dir = input()
	x = y = 0
	res = 0
	s = set()
	for d in dir:
		px = x
		py = y
		if d == 'N':
			y += 1
		elif d == 'S':
			y -= 1
		elif d == 'E':
			x += 1
		else:
			x -= 1
		l1 = [px, py, x, y]
		l2 = [x, y, px, py]
		if tuple(l1) in s:
			res += 1
		else:
			res += 5
		s.add(tuple(l1))
		s.add(tuple(l2))
	print(res)
	t -= 1


direction = {'N': (0, +1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
for _ in range(int(input())):
	path = input()
	visited = set()
	(px, py) = (0, 0)
	tick = 0
	for d in path:
		(ox, oy) = (px, py)
		(dx, dy) = direction[d]
		px += dx
		py += dy
		if (ox, oy, px, py) in visited or (px, py, ox, oy) in visited:
			tick += 1
		else:
			tick += 5
			visited.add((ox, oy, px, py))
			visited.add((px, py, ox, oy))
	print(tick)


t = int(input())
for test in range(t):
	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)


INT_MAX = 10 ** 11 + 7
MOD = 10 ** 9 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]
GETA = 123
for _ in range(int(input())):
	s = input()
	A = set()
	x = 0
	y = 0
	d = 0
	prev = (0, 0)
	for e in s:
		if e == 'N':
			y += 1
		elif e == 'S':
			y -= 1
		elif e == 'E':
			x += 1
		else:
			x -= 1
		path = (prev[0], x, prev[1], y)
		path2 = (x, prev[0], prev[1], y)
		path3 = (prev[0], x, y, prev[1])
		path4 = (x, prev[0], prev[1], y)
		if path in A or path2 in A or path3 in A or (path4 in A):
			d += 1
		else:
			d += 5
			A.add(path)
		prev = (x, y)
	print(d)


from collections import defaultdict
mo = [(1, 0), (0, 1), (-1, 0), (0, -1)]
m = {'S': 0, 'N': 2, 'E': 1, 'W': 3}
t = int(input())

def do(i):
	if i == 0:
		return 2
	if i == 2:
		return 0
	if i == 1:
		return 3
	return 1
for _ in range(t):
	s = str(input())
	vi = defaultdict(lambda : [False, False, False, False])
	vi.clear()
	ans = 0
	now = (0, 0)
	for i in s:
		d = do(m[i])
		vi[now][d] = True
		now = (now[0] + mo[m[i]][0], now[1] + mo[m[i]][1])
		if vi[now][m[i]]:
			ans += 1
		else:
			ans += 5
			vi[now][m[i]] = True
	print(ans)


import sys
for t in range(int(sys.stdin.readline())):
	ans = 0
	ways = set()
	(x, y) = (0, 0)
	a = sys.stdin.readline()[:-1]
	for ch in a:
		(x0, y0) = (x, y)
		if ch == 'W':
			x0 += 1
		elif ch == 'E':
			x0 -= 1
		elif ch == 'N':
			y0 += 1
		else:
			y0 -= 1
		if x > x0:
			(x1, x2) = (x0, x)
		else:
			(x2, x1) = (x0, x)
		if y > y0:
			(y1, y2) = (y0, y)
		else:
			(y2, y1) = (y0, y)
		if (x1, x2, y1, y2) in ways:
			ans += 1
		else:
			ans += 5
			ways.add((x1, x2, y1, y2))
		x = x0
		y = y0
	sys.stdout.write('{}\n'.format(ans))


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

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(chars):
	x0 = 0
	y0 = 0
	paths = set()
	time = 0
	for c in chars:
		if c == 'N':
			y = y0 + 1
			x = x0
		if c == 'S':
			y = y0 - 1
			x = x0
		if c == 'E':
			x = x0 + 1
			y = y0
		if c == 'W':
			x = x0 - 1
			y = y0
		path = (x0, y0, x, y)
		path_mir = (x, y, x0, y0)
		if path in paths or path_mir in paths:
			time += 1
		else:
			time += 5
		paths.add(path)
		x0 = x
		y0 = y
	return time
t = read_int()
for case in range(t):
	chars = input()
	sol = solve(chars)
	print(sol)


for _ in range(int(input())):
	s = input()
	d = []
	d = set(d)
	(a, b) = (0, 0)
	(x, y) = (0, 0)
	ans = 0
	for i in s:
		if i == 'N':
			y = b + 1
		elif i == 'S':
			y = b - 1
		elif i == 'E':
			x = a + 1
		else:
			x = a - 1
		if (a, b, x, y) in d or (x, y, a, b) in d:
			ans += 1
		else:
			ans += 4 + 1
		d.add((a, b, x, y))
		(a, b) = (x, y)
	print(ans)


t = int(input())
for tests in range(t):
	s = input()
	d = dict()
	(tecx, tecy) = (0, 0)
	ismx = [1, -1, 0, 0]
	ismy = [0, 0, -1, 1]
	strr = 'NSWE'
	count = 0
	for i in s:
		op = strr.index(i)
		(tecx1, tecy1) = (tecx + ismx[op], tecy + ismy[op])
		if (tecx, tecy, tecx1, tecy1) not in d:
			count += 5
			d[tecx, tecy, tecx1, tecy1] = 1
			d[tecx1, tecy1, tecx, tecy] = 1
		else:
			count += 1
		(tecx, tecy) = (tecx1, tecy1)
	print(count)


import sys
dir = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
cin = sys.stdin.buffer.readline
for _ in range(int(cin())):
	s = input()
	ans = 0
	d = set()
	(x, y) = (0, 0)
	for i in s:
		u = x + dir[i][0]
		v = y + dir[i][1]
		if (x, y, u, v) in d or (u, v, x, y) in d:
			ans += 1
		else:
			ans += 5
			d.add((x, y, u, v))
		(x, y) = (u, v)
	print(ans)


for T in range(int(input())):
	s = input()
	cord = [0, 0]
	visit = set()
	time = 0
	for c in s:
		(x, y) = (cord[0], cord[1])
		if c == 'N':
			cord[0] += 1
		elif c == 'S':
			cord[0] -= 1
		elif c == 'W':
			cord[1] += 1
		else:
			cord[1] -= 1
		tup = (min(x, cord[0]), max(x, cord[0]), min(y, cord[1]), max(y, cord[1]))
		if tup in visit:
			time += 1
		else:
			visit.add(tup)
			time += 5
	print(time)


from math import gcd, ceil
from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

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

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def pred(n, k, pointer):
	return pointer - k >= n
for _ in range(inin()):
	vis = dd(bool)
	(x1, y1) = (0, 0)
	s = input()
	su = 0
	for i in s:
		(x, y) = (x1, y1)
		if i == 'N':
			y += 1
		if i == 'S':
			y -= 1
		if i == 'W':
			x -= 1
		if i == 'E':
			x += 1
		if vis[x1, y1, x, y]:
			su += 1
		else:
			vis[x, y, x1, y1] = True
			vis[x1, y1, x, y] = True
			su += 5
		x1 = x
		y1 = y
	print(su)


t = int(input())
Q = []
for j in range(t):
	s = input()
	D = dict()
	x = 0
	y = 0
	p = x
	q = y
	Sum = 5 * len(s)
	for i in range(len(s)):
		if s[i] == 'N':
			y += 1
		elif s[i] == 'S':
			y -= 1
		elif s[i] == 'W':
			x -= 1
		else:
			x += 1
		flag1 = 0
		if (x, y) in D:
			for elem in D[x, y]:
				if elem == (p, q):
					Sum -= 4
					flag1 += 1
		B = set()
		if (p, q) not in D:
			D[p, q] = B
			B.add((x, y))
		else:
			flag = 0
			if flag1 == 0:
				for elem in D[p, q]:
					if elem == (x, y):
						Sum -= 4
						flag += 1
			if flag == 0:
				D[p, q].add((x, y))
		p = x
		q = y
	Q.append(Sum)
for m in range(len(Q)):
	print(Q[m])


MOD = 1000000007
mod = 10009
import math

def primeseive(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	ans = [i for i in range(2, n + 1) if prime[i]]
	print(ans)

def checkprime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def xymodm(x, y, m):
	res = 1
	x = x % m
	if x == 0:
		return 0
	while y > 0:
		if y & 1:
			res = res * x % m
		y = y // 2
		x = x * x % m
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def subarray(a):
	sub = [[]]
	for item in sorted(a):
		sub += [prevsub + [item] for prevsub in sub]
	return sorted(sub)

def check(a, b, c, d):
	ans = 0
	cnt = b
	ind = 0.0
	flag = True
	if a <= b:
		ans = b
	elif a > b:
		if c - d < 0:
			ans = -1
		else:
			ind = (a - b) / (c - d)
			ans = math.ceil(ind)
			ans = ans * c + b
	print(ans)

def solve(s):
	dic = {}
	x = 0
	y = 0
	ans = 0
	dic[x, y] = 1
	for i in s:
		inix = x
		iniy = y
		if i == 'N':
			y += 1
		elif i == 'S':
			y -= 1
		elif i == 'W':
			x -= 1
		elif i == 'E':
			x += 1
		if (inix, iniy, x, y) in dic:
			ans += 1
		else:
			dic[inix, iniy, x, y] = 1
			dic[x, y, inix, iniy] = 1
			ans += 5
	print(ans)
for i in range(int(input())):
	s = input()
	solve(s)


for _ in range(int(input())):
	(ans, x, y) = (0, 0, 0)
	s = set()
	for c in input():
		(nx, ny) = (x, y)
		if c == 'N':
			ny += 1
		if c == 'S':
			ny -= 1
		if c == 'W':
			nx -= 1
		if c == 'E':
			nx += 1
		if (x, y, nx, ny) not in s:
			ans += 5
			s.add((x, y, nx, ny))
			s.add((nx, ny, x, y))
		else:
			ans += 1
		(x, y) = (nx, ny)
	print(ans)


t = int(input())
for i in range(t):
	(x, y) = (0, 0)
	s = input()
	d = {}
	for i in range(len(s)):
		x1 = x
		y1 = y
		l = [(x1, y1)]
		if s[i] == 'N':
			x = x + 1
		if s[i] == 'S':
			x = x - 1
		if s[i] == 'W':
			y = y + 1
		if s[i] == 'E':
			y = y - 1
		l.append((x, y))
		l.sort()
		r = tuple(l)
		d[r] = 1
	cnt = len(d) * 5 + (len(s) - len(d))
	print(cnt)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	s = data()
	(x, y) = (0, 0)
	answer = 0
	temp = set()
	for i in s:
		(t1, t2) = (x, y)
		if i == 'N':
			y += 1
		if i == 'E':
			x += 1
		if i == 'W':
			x -= 1
		if i == 'S':
			y -= 1
		if (t1, t2, x, y) in temp:
			answer += 1
		else:
			answer += 5
		temp.add((t1, t2, x, y))
		temp.add((x, y, t1, t2))
	out(answer)


t = int(input())
for _ in range(t):
	s = input()
	lst = set()
	tt = 0
	s1 = ''
	(x, y) = (0, 0)
	if len(set(s)) == 1:
		print(5 * len(s))
	else:
		for i in s:
			if i == 'N':
				x1 = x
				y1 = y + 1
			elif i == 'S':
				x1 = x
				y1 = y - 1
			elif i == 'E':
				x1 = x + 1
				y1 = y
			else:
				x1 = x - 1
				y1 = y
			a = (x, y)
			b = (x1, y1)
			if a + b in lst:
				tt += 1
			else:
				tt += 5
				lst.add(a + b)
				lst.add(b + a)
			x = x1
			y = y1
		print(tt)


directions = {'N': [0, 1], 'S': [0, -1], 'E': [1, 0], 'W': [-1, 0]}
t = int(input())
for _ in range(t):
	time = 0
	path = set()
	(x, y) = (0, 0)
	for k in input():
		x1 = x + directions[k][0]
		y1 = y + directions[k][1]
		if (x, y, x1, y1) not in path and (x1, y1, x, y) not in path:
			time += 5
			path.add((x1, y1, x, y))
		else:
			time += 1
		(x, y) = (x1, y1)
	print(time)


import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor
from collections import Counter
from math import gcd

def main():
	for _ in range(int(input())):
		s = input()
		st = set()
		x = y = cnt = 0
		for (ind, i) in enumerate(s):
			c_x = x
			c_y = y
			if i == 'N':
				x += 1
			elif i == 'S':
				x -= 1
			elif i == 'W':
				y += 1
			else:
				y -= 1
			if (c_x, c_y, x, y) in st or (x, y, c_x, c_y) in st:
				cnt += 1
			st.add((c_x, c_y, x, y))
		print(5 * len(s) - 4 * cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	t = int(input())
	for _ in range(t):
		directions = input()
		time = 0
		x1 = 0
		x2 = 0
		y1 = 0
		y2 = 0
		places_been = {((0, 0), (0, 0))}
		if len(set(directions)) == 1:
			print(len(directions) * 5)
			continue
		for direction in directions:
			if direction == 'N':
				x1 = x2
				y1 = y2
				y2 += 1
				if ((x1, y1), (x2, y2)) in places_been:
					time += 1
				else:
					time += 5
					places_been.add(((x1, y1), (x2, y2)))
					places_been.add(((x2, y2), (x1, y1)))
			elif direction == 'S':
				x1 = x2
				y1 = y2
				y2 -= 1
				if ((x1, y1), (x2, y2)) in places_been:
					time += 1
				else:
					time += 5
					places_been.add(((x1, y1), (x2, y2)))
					places_been.add(((x2, y2), (x1, y1)))
			elif direction == 'E':
				x1 = x2
				y1 = y2
				x2 += 1
				if ((x1, y1), (x2, y2)) in places_been:
					time += 1
				else:
					time += 5
					places_been.add(((x1, y1), (x2, y2)))
					places_been.add(((x2, y2), (x1, y1)))
			else:
				x1 = x2
				y1 = y2
				x2 -= 1
				if ((x1, y1), (x2, y2)) in places_been:
					time += 1
				else:
					time += 5
					places_been.add(((x1, y1), (x2, y2)))
					places_been.add(((x2, y2), (x1, y1)))
		print(time)
main()


t = int(input())
i = 0
dic = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
while i < t:
	s = input()
	count = 0
	(x, y) = (0, 0)
	ad = set()
	for j in s:
		x1 = x + dic[j][0]
		y1 = y + dic[j][1]
		if (x, y, x1, y1) in ad or (x1, y1, x, y) in ad:
			count = count + 1
		else:
			count = count + 5
			ad.add((x, y, x1, y1))
		(x, y) = (x1, y1)
	print(count)
	i = i + 1


import sys
import math

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

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

def inputstring():
	return [x for x in input()]
t = int(input())
for q in range(t):
	path = inputstring()
	pos = (0, 0)
	ans = 0
	passed = set()
	d = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
	for char in path:
		(x1, y1) = pos
		(x2, y2) = d[char]
		(x3, y3) = (x1 + x2, y1 + y2)
		pos = (x3, y3)
		if ((x1, y1), (x3, y3)) in passed:
			ans += 1
		else:
			ans += 5
			passed.add(((x1, y1), (x3, y3)))
			passed.add(((x3, y3), (x1, y1)))
	print(ans)


def solve():
	s = input()
	start = [0, 0]
	visited = set()
	moveMap = {'N': [-1, 0], 'S': [1, 0], 'W': [0, -1], 'E': [0, 1]}
	counter = 0
	for i in s:
		move = [a + b for (a, b) in zip(start, moveMap[i])]
		visit = [a + b for (a, b) in zip(start, move)]
		if tuple(visit) in visited:
			counter += 1
		else:
			counter += 5
			visited.add(tuple(visit))
		start = move
	print(counter)
t = int(input())
for _ in range(t):
	solve()


import sys, math
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		s = input().replace('\n', '')
		se = set()
		inc = 0
		co = (0, 0)
		se.add((co, co))
		for x in range(len(s)):
			last_co = co
			if s[x] == 'N':
				co = (co[0] + 1, co[1])
			if s[x] == 'S':
				co = (co[0] - 1, co[1])
			if s[x] == 'W':
				co = (co[0], co[1] - 1)
			if s[x] == 'E':
				co = (co[0], co[1] + 1)
			if True:
				if (co, last_co) in se:
					inc += 1
				else:
					se.add((last_co, co))
					se.add((co, last_co))
					inc += 5
		print(inc)
main()


q = int(input())
dupa = 3
for _ in range(q):
	s = input()
	odc = []
	cur = [0, 0]
	n = len(s)
	for i in range(n):
		prev = cur.copy()
		if s[i] == 'N':
			cur[1] += 1
		if s[i] == 'S':
			cur[1] -= 1
		if s[i] == 'W':
			cur[0] -= 1
		if s[i] == 'E':
			cur[0] += 1
		pyk = [[cur[0], cur[1]], [prev[0], prev[1]]]
		if pyk[0] > pyk[1]:
			a = pyk[0]
			b = pyk[1]
			pyk = [b, a]
		odc.append(pyk)
	odc.sort()
	wyn = 5
	for i in range(1, n):
		if odc[i] == odc[i - 1]:
			wyn += 1
		else:
			wyn += 5
	print(wyn)


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 solve(s):
	req_set = set(s)
	if len(req_set) == 1:
		return 5 * len(s)
	req_list = list(s)
	cost = 0
	(x, y) = (0, 0)
	(px, py) = (x, y)
	path = {}
	for i in range(len(req_list)):
		if req_list[i] == 'N':
			y += 1
		elif req_list[i] == 'S':
			y -= 1
		elif req_list[i] == 'W':
			x -= 1
		else:
			x += 1
		if path.get(((px, py), (x, y))) or path.get(((x, y), (px, py))):
			cost += 1
		else:
			path[(px, py), (x, y)] = 1
			path[(x, y), (px, py)] = 1
			cost += 5
		(px, py) = (x, y)
	return cost
T = int(input())
for _ in range(T):
	s = input()
	print(solve(s))


for _ in range(int(input())):
	l = input()
	d = {}
	x = 0
	y = 0
	a = 0
	b = 0
	d[(0, 0), (0, 0)] = 1
	ans = 0
	for t in l:
		a = x
		b = y
		if t == 'N':
			y += 1
		if t == 'S':
			y -= 1
		if t == 'E':
			x += 1
		if t == 'W':
			x -= 1
		if ((a, b), (x, y)) not in d and ((x, y), (a, b)) not in d:
			ans += 5
			d[(a, b), (x, y)] = 1
			d[(x, y), (a, b)] = 1
		else:
			ans += 1
	print(ans)


T = int(input())
x_dir = [0, 0, 1, -1]
y_dir = [1, -1, 0, 0]
direction_str = 'NSWE'
direction_map = dict()
oppo = dict()
oppo_str = 'SNEW'
for i in range(4):
	oppo[direction_str[i]] = oppo_str[i]
for i in range(4):
	direction_map[direction_str[i]] = i
for t in range(T):
	visited = set()
	s = input()
	x = 0
	y = 0
	ans = 0
	for i in s:
		move = direction_map[i]
		x += x_dir[move]
		y += y_dir[move]
		if (x, y, oppo[i]) in visited:
			ans += 1
		else:
			ans += 5
			if x_dir[move] > 0:
				visited.add((x - 1, y, 'W'))
				visited.add((x, y, 'E'))
			elif x_dir[move] < 0:
				visited.add((x + 1, y, 'E'))
				visited.add((x, y, 'W'))
			elif y_dir[move] > 0:
				visited.add((x, y - 1, 'N'))
				visited.add((x, y, 'S'))
			else:
				visited.add((x, y + 1, 'S'))
				visited.add((x, y, 'N'))
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	s = input()
	d = defaultdict(int)
	(px, py, res) = (0, 0, 0)
	for x in s:
		if x == 'E':
			nx = px + 1
			ny = py
		elif x == 'W':
			nx = px - 1
			ny = py
		elif x == 'N':
			nx = px
			ny = py + 1
		elif x == 'S':
			nx = px
			ny = py - 1
		if ((px, py), (nx, ny)) in d:
			res += 1
		elif ((nx, ny), (px, py)) in d:
			res += 1
		else:
			d[(nx, ny), (px, py)] += 1
			d[(px, py), (nx, ny)] += 1
			res += 5
		(px, py) = (nx, ny)
	print(res)


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):
	ip = input().rstrip()
	i = 0
	j = 0
	hist = {}
	cost = 0
	for d in ip:
		if d == 'N':
			ni = i + 1
			nj = j
		elif d == 'S':
			ni = i - 1
			nj = j
		elif d == 'E':
			ni = i
			nj = j + 1
		elif d == 'W':
			ni = i
			nj = j - 1
		if (i, j, ni, nj) not in hist:
			cost += 5
			hist[i, j, ni, nj] = 1
			hist[ni, nj, i, j] = 1
		else:
			cost += 1
		i = ni
		j = nj
	print(cost)


for _ in range(int(input())):
	s = input()
	visited = {}
	curr = [0, 0]
	last = curr[:]
	time = 0
	for i in s.rstrip('\n'):
		if i == 'N':
			curr[0] += 1
		elif i == 'S':
			curr[0] -= 1
		elif i == 'W':
			curr[1] += 1
		else:
			curr[1] -= 1
		if tuple(sorted([tuple(last), tuple(curr)])) in visited:
			time += 1
		else:
			visited[tuple(sorted([tuple(last), tuple(curr)]))] = 1
			time += 5
		last = curr[:]
	print(time)


t = int(input())
x = 0
for _ in range(t):
	s = input()
	d = {}
	n = 0
	ans = 0
	w = 0
	for i in range(len(s)):
		x = n
		y = w
		if s[i] == 'N':
			n += 1
		elif s[i] == 'S':
			n -= 1
		elif s[i] == 'W':
			w -= 1
		else:
			w += 1
		if (n, w, x, y) in d or (x, y, n, w) in d:
			ans += 1
		else:
			ans += 5
			d[n, w, x, y] = 1
	print(ans)


I = input
for _ in range(int(I())):
	l = list(I())
	d = {(0, 0, 0, 0): 1}
	x = 0
	y = 0
	ans = 0
	x1 = 0
	y1 = 0
	for i in range(len(l)):
		if l[i] == 'N':
			x += 1
		elif l[i] == 'S':
			x -= 1
		elif l[i] == 'W':
			y += 1
		elif l[i] == 'E':
			y -= 1
		if (x1, y1, x, y) in d or (x, y, x1, y1) in d:
			ans += 1
		else:
			ans += 5
			d[x1, y1, x, y] = 1
		x1 = x
		y1 = y
	print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	coor = {}
	s = list(inp())
	ans = 0
	curr = [0, 0]
	for i in range(len(s)):
		prev = deepcopy(curr)
		if s[i] == 'N':
			curr[1] += 1
		if s[i] == 'S':
			curr[1] -= 1
		if s[i] == 'W':
			curr[0] += 1
		if s[i] == 'E':
			curr[0] -= 1
		if str(prev[0]) + ' ' + str(prev[1]) + ' ' + str(curr[0]) + ' ' + str(curr[1]) in coor or str(curr[0]) + ' ' + str(curr[1]) + ' ' + str(prev[0]) + ' ' + str(prev[1]) in coor:
			ans += 1
		else:
			ans += 5
		coor[str(prev[0]) + ' ' + str(prev[1]) + ' ' + str(curr[0]) + ' ' + str(curr[1])] = True
		coor[str(curr[0]) + ' ' + str(curr[1]) + ' ' + str(prev[0]) + ' ' + str(prev[1])] = True
	print(ans)
testcase(int(inp()))


def join_vecs(a, b):
	out = a.copy()
	for i in range(len(b)):
		out.append(b[i])
	return out

def get_vecs(point, operation):
	curr_point = point.copy()
	if operation == 'N':
		point[1] = point[1] + 1
	if operation == 'S':
		point[1] = point[1] - 1
	if operation == 'E':
		point[0] = point[0] + 1
	if operation == 'W':
		point[0] = point[0] - 1
	vec_1 = 'x'.join(list(map(lambda x: str(x), curr_point))) + 'x'.join(list(map(lambda x: str(x), point)))
	vec_2 = 'x'.join(list(map(lambda x: str(x), point))) + 'x'.join(list(map(lambda x: str(x), curr_point)))
	return (vec_1, vec_2, point)

def solve(operations):
	curr_point = [0, 0]
	NS_vectors = []
	EW_vectors = []
	k = 0
	for operation in operations:
		(vec_1, vec_2, curr_point) = get_vecs(curr_point, operation)
		if (operation == 'N') | (operation == 'S'):
			NS_vectors.append(vec_1)
			NS_vectors.append(vec_2)
		if (operation == 'E') | (operation == 'W'):
			EW_vectors.append(vec_1)
			EW_vectors.append(vec_2)
	k += int((len(NS_vectors) - len(set(NS_vectors))) / 2) + int(len(set(NS_vectors)) / 2) * 5
	k += int((len(EW_vectors) - len(set(EW_vectors))) / 2) + int(len(set(EW_vectors)) / 2) * 5
	return str(k)
t = int(input())
answers = []
for i in range(t):
	operations = input()
	answers.append(solve(operations))
print('\n'.join(answers))


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['YES', 'NO']
test_case = ii()
while test_case:
	test_case -= 1
	a = lsi()
	s = set()
	x = y = 0
	for i in a:
		u = v = 0
		if i == 'N':
			u = 1
		elif i == 'S':
			u = -1
		elif i == 'E':
			v = 1
		else:
			v = -1
		s.add((x, y, x + u, y + v))
		s.add((x + u, y + v, x, y))
		x += u
		y += v
	print(5 * len(s) // 2 + len(a) - len(s) // 2)


from collections import defaultdict
t = int(input())
for _ in range(t):
	s = input()
	x = 0
	y = 0
	d = defaultdict(int)
	v = 0
	for i in s:
		if i == 'N':
			y -= 1
			d[(x, y), (x, y + 1)] += 1
			d[(x, y + 1), (x, y)] += 1
		if i == 'S':
			y += 1
			d[(x, y), (x, y - 1)] += 1
			d[(x, y - 1), (x, y)] += 1
		if i == 'E':
			x += 1
			d[(x, y), (x - 1, y)] += 1
			d[(x - 1, y), (x, y)] += 1
		if i == 'W':
			x -= 1
			d[(x, y), (x + 1, y)] += 1
			d[(x + 1, y), (x, y)] += 1
	for (k, val) in d.items():
		v += 5 + (val - 1)
	print(v // 2)


import os
import sys
from io import BytesIO, IOBase

def solution(s):
	coords = set()
	res = 0
	(i, j) = (0, 0)
	prev = (i, j)
	for c in s:
		(x, y) = prev
		if c == 'N':
			y += 1
		elif c == 'E':
			x += 1
		elif c == 'W':
			x -= 1
		else:
			y -= 1
		if (prev, (x, y)) in coords or ((x, y), prev) in coords:
			res += 1
		else:
			coords.add((prev, (x, y)))
			res += 5
		prev = (x, y)
	write(res)

def main():
	for _ in range(r_int()):
		s = input()
		solution(s)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


t = int(input())
ans = list()
for _ in range(t):
	line = input()
	vect = [0, 0, 'N']
	time = 0
	s = set()
	for x in line:
		vect[2] = x
		tmp = vect[:]
		if vect[2] == 'N':
			tmp[1] += 1
			tmp[2] = 'S'
		elif vect[2] == 'S':
			tmp[1] -= 1
			tmp[2] = 'N'
		elif vect[2] == 'E':
			tmp[0] += 1
			tmp[2] = 'W'
		elif vect[2] == 'W':
			tmp[0] -= 1
			tmp[2] = 'E'
		if tuple(vect) in s:
			time += 1
		else:
			s.add(tuple(vect))
			s.add(tuple(tmp))
			time += 5
		vect = tmp
	ans.append(time)
for x in ans:
	print(x)


for u in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	c = 0
	l = set()
	for i in s:
		(xx, yy) = (x, y)
		if i == 'N':
			yy = yy + 1
		elif i == 'S':
			yy = yy - 1
		elif i == 'E':
			xx = xx + 1
		elif i == 'W':
			xx = xx - 1
		ka = (x, y, xx, yy)
		ak = (xx, yy, x, y)
		if ka in l:
			c = c + 1
		else:
			c = c + 5
		l.add(ka)
		l.add(ak)
		(x, y) = (xx, yy)
	print(c)


t = int(input())
for w in range(t):
	s = input()
	time = 0
	s1 = set()
	(x, y) = (0, 0)
	for i in s:
		(x1, y1) = (0, 0)
		if i == 'N':
			x1 += 1
		elif i == 'S':
			x1 -= 1
		elif i == 'W':
			y1 += 1
		else:
			y1 -= 1
		if (x, y, x + x1, y + y1) not in s1 and (x + x1, y + y1, x, y) not in s1:
			time += 5
		else:
			time += 1
		s1.add((x, y, x1 + x, y1 + y))
		s1.add((x1 + x, y1 + y, x, y))
		x += x1
		y += y1
	print(time)


for i in range(int(input())):
	coord = (0, 0)
	m = {}
	time = 0
	direcs = list(input())
	for d in direcs:
		if d == 'N':
			n_coord = (coord[0], coord[1] + 1)
		elif d == 'W':
			n_coord = (coord[0] - 1, coord[1])
		elif d == 'E':
			n_coord = (coord[0] + 1, coord[1])
		elif d == 'S':
			n_coord = (coord[0], coord[1] - 1)
		if coord in m and n_coord in m[coord] or (n_coord in m and coord in m[n_coord]):
			time += 1
		else:
			time += 5
			if coord in m:
				m[coord].append(n_coord)
			elif n_coord in m:
				m[n_coord].append(coord)
			else:
				m[coord] = [n_coord]
		coord = n_coord
	print(time)


for _ in range(int(input())):
	a = list(input())
	(x, y) = (0, 0)
	ans = 0
	visited = {}
	for i in range(len(a)):
		aa = (x, y)
		if a[i] == 'N':
			y += 1
		elif a[i] == 'S':
			y -= 1
		elif a[i] == 'E':
			x += 1
		else:
			x -= 1
		bb = (x, y)
		if (aa, bb) in visited or (bb, aa) in visited:
			ans += 1
		else:
			ans += 5
			visited[aa, bb] = 1
			visited[bb, aa] = 1
	print(ans)


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)


import sys
n = int(sys.stdin.readline())
tests = sys.stdin.readlines()

def solve(testcase):
	x = 0
	y = 0
	typeA = 0
	typeB = 0
	visitedNS = set()
	visitedEW = set()
	for c in testcase:
		if c == 'N':
			if (x, y) in visitedNS:
				typeB += 1
			else:
				typeA += 1
				visitedNS.add((x, y))
			y += 1
		if c == 'S':
			if (x, y - 1) in visitedNS:
				typeB += 1
			else:
				typeA += 1
				visitedNS.add((x, y - 1))
			y -= 1
		if c == 'W':
			if (x, y) in visitedEW:
				typeB += 1
			else:
				typeA += 1
				visitedEW.add((x, y))
			x += 1
		if c == 'E':
			if (x - 1, y) in visitedEW:
				typeB += 1
			else:
				typeA += 1
				visitedEW.add((x - 1, y))
			x -= 1
	print(typeA * 5 + typeB)
for testcase in tests:
	solve(testcase)


def rolltime(string):
	time = 0
	x = 0
	y = 0
	aimed_x = 0
	aimed_y = 0
	visited = set()
	for step in string:
		if step == 'N':
			aimed_x = x
			aimed_y = y + 1
		if step == 'S':
			aimed_x = x
			aimed_y -= 1
		if step == 'E':
			aimed_y = y
			aimed_x = x + 1
		if step == 'W':
			aimed_y = y
			aimed_x = x - 1
		if frozenset({(x, y), (aimed_x, aimed_y)}) in visited:
			time += 1
		else:
			time += 5
			visited.add(frozenset({(x, y), (aimed_x, aimed_y)}))
		(x, y) = (aimed_x, aimed_y)
	return time
t = int(input())
strings = []
for i in range(t):
	strings.append(input())
for i in range(t):
	print(rolltime(strings[i]))


(t,) = map(int, input().split())
for _ in range(t):
	s = input().strip()
	p = (0, 0)
	d = set()
	r = 0
	for c in s:
		if c == 'N':
			x = (p[0], p[1], p[0], p[1] + 1)
			p = (p[0], p[1] + 1)
		elif c == 'S':
			x = (p[0], p[1] - 1, p[0], p[1])
			p = (p[0], p[1] - 1)
		elif c == 'E':
			x = (p[0], p[1], p[0] + 1, p[1])
			p = (p[0] + 1, p[1])
		else:
			x = (p[0] - 1, p[1], p[0], p[1])
			p = (p[0] - 1, p[1])
		if x in d:
			r += 1
		else:
			r += 5
			d.add(x)
	print(r)


def resolve(x, y):
	num = 100000
	return x + y * num
t = int(input())
for i in range(t):
	s = input()
	a = set()
	b = set()
	x = 0
	y = 0
	ans = 0
	for i in s:
		if i == 'N':
			(x, y) = (x, y + 1)
			if resolve(x, y) in a:
				ans += 1
			else:
				ans += 5
				a.add(resolve(x, y))
		elif i == 'S':
			if resolve(x, y) in a:
				ans += 1
			else:
				ans += 5
				a.add(resolve(x, y))
			(x, y) = (x, y - 1)
		elif i == 'W':
			(x, y) = (x + 1, y)
			if resolve(x, y) in b:
				ans += 1
			else:
				ans += 5
				b.add(resolve(x, y))
		else:
			if resolve(x, y) in b:
				ans += 1
			else:
				ans += 5
				b.add(resolve(x, y))
			(x, y) = (x - 1, y)
	print(ans)


import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		s = sin()
		x = set()
		c = 0
		ix = 0
		iy = 0
		p = 0
		for i in s:
			if i == 'N':
				p = (ix, ix, min(iy, iy + 1), max(iy, iy + 1))
				iy += 1
			elif i == 'S':
				p = (ix, ix, min(iy, iy - 1), max(iy, iy - 1))
				iy -= 1
			elif i == 'E':
				p = (min(ix, ix + 1), max(ix, ix + 1), iy, iy)
				ix += 1
			else:
				p = (min(ix, ix - 1), max(ix, ix - 1), iy, iy)
				ix -= 1
			if p in x:
				c += 1
			else:
				c += 5
				x.add(p)
		print(c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for f in range(int(input())):
	path = input()
	n = len(path)
	used = set()
	previ = 0
	prevj = 0
	sol = 0
	for k in range(n):
		i = previ
		j = prevj
		if path[k] == 'S':
			i += 1
		if path[k] == 'N':
			i -= 1
		if path[k] == 'W':
			j += 1
		if path[k] == 'E':
			j -= 1
		pat = ((i, j), (previ, prevj))
		if pat in used:
			sol += 1
		else:
			sol += 5
			used.add(pat)
			used.add(((previ, prevj), (i, j)))
		previ = i
		prevj = j
	print(sol)


d = {'S': (0, -1), 'W': (-1, 0), 'N': (0, 1), 'E': (1, 0)}
cases = int(input())
for t in range(cases):
	s = input()
	(x, y) = (0, 0)
	v = 0
	book = {}
	for i in s:
		(dx, dy) = d[i]
		(px, py) = (x, y)
		(x, y) = (x + dx, y + dy)
		if (px, py, x, y) in book or (x, y, px, py) in book:
			v += 1
		else:
			book[px, py, x, y] = True
			v += 5
	print(v)


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


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
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	done = {}
	(x, y, ans) = (0, 0, 0)
	for c in SI():
		(xx, yy) = (x, y)
		if c == 'N':
			yy += 1
		elif c == 'S':
			yy -= 1
		elif c == 'W':
			xx -= 1
		else:
			xx += 1
		p = str(x) + str(',') + str(y) + '-' + str(xx) + str(',') + str(yy)
		pp = str(xx) + str(',') + str(yy) + '-' + str(x) + str(',') + str(y)
		if done.get(p, False) or done.get(pp, False):
			ans += 1
		else:
			ans += 5
		done[p] = done[pp] = True
		(x, y) = (xx, yy)
	print(ans)


dict = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
for _ in range(int(input())):
	s = input()
	st = set()
	(x, y, ans) = (0, 0, 0)
	for i in s:
		x1 = x + dict[i][0]
		y1 = y + dict[i][1]
		if (x, y, x1, y1) in st or (x1, y1, x, y) in st:
			ans += 1
		else:
			ans += 5
			st.add((x, y, x1, y1))
		(x, y) = (x1, y1)
	print(ans)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
for _ in range(int(input())):
	s = input()
	(x, y) = (0, 0)
	(lx, ly) = (0, 0)
	ans = 0
	se = set()
	for i in s:
		(lx, ly) = (x, y)
		if i == 'N':
			x += 1
		elif i == 'S':
			x -= 1
		elif i == 'E':
			y += 1
		else:
			y -= 1
		if (x, y, lx, ly) in se:
			ans += 1
		else:
			ans += 5
			se.add((x, y, lx, ly))
			se.add((lx, ly, x, y))
	print(ans)


t = int(input())
while t:
	t -= 1
	s = input()
	r = set()
	last = [0, 0]
	count = 0
	for i in s:
		if i == 'N':
			new = [last[0] + 1, last[1]]
		elif i == 'S':
			new = [last[0] - 1, last[1]]
		elif i == 'W':
			new = [last[0], last[1] + 1]
		else:
			new = [last[0], last[1] - 1]
		if (new[0], new[1], last[0], last[1]) in r or (last[0], last[1], new[0], new[1]) in r:
			count += 1
		else:
			count += 5
			r.add((new[0], new[1], last[0], last[1]))
		last = new
	print(count)


import sys
from time import *
from math import *
from bisect import bisect_left as bl, bisect_right as br, bisect, insort, insort_left, insort_right
INF = float('inf')
MOD = 998244353
mod = 10 ** 9 + 7
from collections import Counter as cc, defaultdict as df, OrderedDict as od
from functools import reduce

def counter(l):
	return dict(cc(l))

def lcm(a, b):
	return int(a * b / gcd(a, b))

def so(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def rev(l):
	return list(reversed(l))

def i3():
	return int(sys.stdin.readline())

def i2():
	return map(int, sys.stdin.readline().strip().split())

def li():
	return list(map(int, sys.stdin.readline().strip().split()))

def i1():
	return sys.stdin.readline().strip()

def inputm(n, m):
	return [li() for i in range(n)]

def zero(n):
	return [0 for i in range(n)]

def zero2(n, m):
	return [[0 for i in range(m)] for j in range(n)]

def yes():
	print('YES')

def no():
	print('NO')

def p(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def main():
	s = i1()
	n = len(s)
	l = df(int)
	cout = 0
	(a, b, c, d) = (0, 0, 0, 0)
	for i in s:
		(c, d) = (a, b)
		if i == 'N':
			a += 1
		elif i == 'S':
			a -= 1
		elif i == 'E':
			b += 1
		elif i == 'W':
			b -= 1
		if l[a, b, c, d] or l[c, d, a, b]:
			cout += 1
		else:
			cout += 5
			l[a, b, c, d] = 1
	print(cout)
for i in range(i3()):
	main()


def reverse_direction(direct):
	if direct == 'N':
		return 'S'
	if direct == 'S':
		return 'N'
	if direct == 'W':
		return 'E'
	return 'W'
for _ in range(int(input())):
	tmp = input()
	path = 0
	coord = (0, 0)
	prices = {coord: {}}
	for direction in tmp:
		if direction not in prices[coord]:
			prices[coord][direction] = 5
		current_price = prices[coord][direction]
		prices[coord][direction] = 1
		path += current_price
		if direction == 'N':
			coord = (coord[0], coord[1] + 5)
		elif direction == 'S':
			coord = (coord[0], coord[1] - 5)
		elif direction == 'W':
			coord = (coord[0] - 5, coord[1])
		else:
			coord = (coord[0] + 5, coord[1])
		if coord in prices:
			prices[coord][reverse_direction(direction)] = 1
		else:
			prices[coord] = {reverse_direction(direction): 1}
	print(path)


def solve():
	s = input()
	visited = set()
	x = 0
	y = 0
	r = 0
	for c in s:
		current = (x, y)
		if c == 'N':
			y += 1
		elif c == 'S':
			y -= 1
		elif c == 'W':
			x -= 1
		else:
			x += 1
		path = (current, (x, y))
		r += 1 if path in visited else 5
		visited.add(path)
		visited.add(((x, y), current))
	print(r)
for _ in range(int(input())):
	solve()