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 ≤ t ≤ 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
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = LLONG_MAX;
void IO() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
}
long long pw(long long x, long long y, long long p = inf) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long invmod(long long a, long long m = mod) { return pw(a, m - 2, m); }
long long cl(long long a, long long x) {
  return a % x == 0 ? a / x : a / x + 1;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void run_time_terror() {
  set<pair<pair<long long, long long>, long long>> mv, mh;
  string s;
  cin >> s;
  long long x = 0, y = 0, ans = 0;
  for (long long i = 0; i < s.length(); ++i) {
    if (s[i] == 'N') {
      if (mv.find({{x, x + 1}, y}) == mv.end() or
          mv.find({{x + 1, x}, y}) == mv.end()) {
        ans += 5;
        mv.insert({{x, x + 1}, y});
        mv.insert({{x + 1, x}, y});
      } else {
        ans += 1;
      }
      x++;
    }
    if (s[i] == 'S') {
      if (mv.find({{x, x - 1}, y}) == mv.end() or
          mv.find({{x - 1, x}, y}) == mv.end()) {
        ans += 5;
        mv.insert({{x, x - 1}, y});
        mv.insert({{x - 1, x}, y});
      } else {
        ans += 1;
      }
      x--;
    }
    if (s[i] == 'E') {
      if (mh.find({{y, y + 1}, x}) == mh.end() or
          mh.find({{y + 1, y}, x}) == mh.end()) {
        ans += 5;
        mh.insert({{y, y + 1}, x});
        mh.insert({{y + 1, y}, x});
      } else {
        ans += 1;
      }
      y++;
    }
    if (s[i] == 'W') {
      if (mh.find({{y, y - 1}, x}) == mh.end() or
          mh.find({{y - 1, y}, x}) == mh.end()) {
        ans += 5;
        mh.insert({{y, y - 1}, x});
        mh.insert({{y - 1, y}, x});
      } else {
        ans += 1;
      }
      y--;
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  cout << setprecision(0);
  IO();
  long long tt = 1;
  cin >> tt;
  for (long long case_no = 1; case_no <= tt; case_no++) {
    run_time_terror();
  }
  return 0;
}
