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;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  for (auto v : V) os << v << " ";
  return cout << "";
}
template <class T>
ostream& operator<<(ostream& os, set<T> S) {
  for (auto s : S) os << s << " ";
  return cout << "";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << P.first << " " << P.second;
}
const long long mod = 998244353;
long long inv(long long i) {
  if (i == 1) return 1;
  return (mod - (mod / i) * inv(mod % i) % mod) % mod;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b, b % a);
}
long long arr[200020], brr[200200];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, n, m, f, f1, f2, t, a, b, k;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    map<pair<pair<long long, long long>, pair<long long, long long>>, long long>
        m;
    long long x[200020], y[200200], x1[200200], y1[200200];
    x[0] = 0;
    y[0] = 0;
    j = 1;
    long long ans = 0;
    for (i = 0; i <= s.length() - 1; i++) {
      if (s[i] == 'N') {
        x[j] = x[j - 1];
        y[j] = y[j - 1] + 1;
        x1[j] = x[j - 1];
        y1[j] = y[j - 1];
      }
      if (s[i] == 'E') {
        x[j] = x[j - 1] + 1;
        y[j] = y[j - 1];
        x1[j] = x[j - 1];
        y1[j] = y[j - 1];
      }
      if (s[i] == 'W') {
        x[j] = x[j - 1] - 1;
        y[j] = y[j - 1];
        x1[j] = x[j - 1];
        y1[j] = y[j - 1];
      }
      if (s[i] == 'S') {
        x[j] = x[j - 1];
        y[j] = y[j - 1] - 1;
        x1[j] = x[j - 1];
        y1[j] = y[j - 1];
      }
      if (m[make_pair(make_pair(x[j], y[j]), make_pair(x1[j], y1[j]))] == 1 or
          m[make_pair(make_pair(x1[j], y1[j]), make_pair(x[j], y[j]))] == 1) {
        ans += 1;
      } else {
        ans += 5;
      }
      m[make_pair(make_pair(x[j], y[j]), make_pair(x1[j], y1[j]))] = 1;
      m[make_pair(make_pair(x1[j], y1[j]), make_pair(x[j], y[j]))] = 1;
      j++;
    }
    cout << ans << "\n";
  }
}
