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 double PI = acos(-1);
long long power(long long a, long long b, long long m = 1000000007) {
  long long ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) ans = (1ll * a * ans) % m;
    b >>= 1;
    a = (1ll * a * a) % m;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
bool isprime(long long n) {
  if (n < 2) return 0;
  long long i = 2;
  while (i * i <= n) {
    if (n % i == 0) return 0;
    i++;
  }
  return 1;
}
bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }
void offset(vector<int>& a, int x) {
  for (int i = 0; i < ((long long)(a).size()); i++) {
    a[i] = x;
  }
}
struct cmp {
  bool operator()(const pair<int, int>& lhs, const pair<int, int>& rhs) const {
    return lhs.first * rhs.second < lhs.second * rhs.first;
  }
};
double distform(int x, int y, int z, int w) {
  return sqrt(1. * pow(x - z, 2) + 1. * pow(y - w, 2));
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
const int MAXN = 2e5 + 10;
bool cmps(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.second > p2.second;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tt;
  cin >> tt;
  while (tt--) {
    string s;
    cin >> s;
    set<pair<long long, long long> > check;
    long long ans = 0;
    long long x = 0, y = 0;
    for (long long i = 0; i < ((long long)(s).size()); ++i) {
      long long px = x;
      long long py = y;
      if (s[i] == 'N') {
        y += 1;
      }
      if (s[i] == 'S') {
        y -= 1;
      }
      if (s[i] == 'E') {
        x += 1;
      }
      if (s[i] == 'W') {
        x -= 1;
      }
      if (check.find({x + px, y + py}) == check.end()) {
        ans += 5;
        check.insert({x + px, y + py});
      } else {
        ans += 1;
      }
    }
    cout << ans << "\n";
  };
  cerr << "\n"
       << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]"
       << "\n";
}
