import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int dirs = 4;
immutable int  [dirs] dRow  = [ -1,   0,  +1,   0];
immutable int  [dirs] dCol  = [  0,  -1,   0,  +1];
immutable char [dirs] dName = ['N', 'W', 'S', 'E'];

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		alias Coord = Tuple !(int, q{row}, int, q{col});
		auto cur = Coord (0, 0);
		bool [Coord] vis;
		int res = 0;
		foreach (char c; s)
		{
			auto dir = dName[].countUntil (c);
			cur.row += dRow[dir];
			cur.col += dCol[dir];
			res += (cur in vis) ? 1 : 5;
			vis[cur] = true;
			cur.row += dRow[dir];
			cur.col += dCol[dir];
		}
		writeln (res);
	}
}
