Problem link
https://codeforces.net/contest/1351/problem/C
submission link https://codeforces.net/contest/1351/submission/109952345
include <bits/stdc++.h>
using namespace std;
define ios ios::sync_with_stdio(false); cin.tie(NULL);
define ll long long
define MOD 1000000007
int main() { ios;
ll t;
cin>>t;
while(t--) { string s; cin>>s; ll x = 0,y=0,n = s.size(); map<pair<ll,ll>,bool>mp; ll ans = 0; for(ll i=0;i<n;i++) { mp[{x,y}] = 1; if(s[i] == 'N') y+= 1; else if(s[i] == 'S') y -= 1; else if(s[i] == 'E') x += 1; else if(s[i] == 'W') x -= 1; if(mp[{x,y}] == 1) ans += 1; else ans += 5; } cout<<ans<<endl; }
return 0;
}