#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int x = 0, y = 0, p, q, sum = 0;
    set<pair<int, int> > ma;
    for (long long int i = 0; i < s.size(); i++) {
      p = x;
      q = y;
      if (s[i] == 'N')
        y++;
      else if (s[i] == 'S')
        y--;
      else if (s[i] == 'W')
        x++;
      else
        x--;
      if (!ma.count({x + p, q + y})) {
        sum = sum + 5;
        ma.insert({x + p, q + y});
      } else
        ++sum;
    }
    cout << sum << endl;
  }
}
