#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long inf = LLONG_MAX;
long double pi = 3.1415926536;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt = 1;
  cin >> tt;
  while (tt--) {
    long long n, x = 0, m = 0, y = 0, k = inf;
    string s;
    cin >> s;
    vector<pair<long long, long long> > v;
    pair<long long, long long> p = {0, 0}, fin = {0, 0};
    map<pair<pair<long long, long long>, pair<long long, long long> >,
        long long>
        vis;
    for (long long i = 0; i < s.length(); i++) {
      if (s[i] == 'N') fin.second++;
      if (s[i] == 'S') fin.second--;
      if (s[i] == 'E') fin.first++;
      if (s[i] == 'W') fin.first--;
      vis[{p, fin}]++;
      vis[{fin, p}]++;
      p = fin;
    }
    long long ans = 0;
    for (auto i : vis) {
      if (i.second == 1) {
        ans += 5;
      } else {
        ans += 5;
        ans += (i.second - 1);
      }
    }
    cout << ans / 2 << '\n';
  }
}
