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 int M = 1000000007;
long long int power(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return (power((x * x) % M, n / 2)) % M;
  else
    return ((x % M) * power(x, n - 1) % M);
}
long long int ncr(int n, int r) {
  if (r > n) return 0;
  if (r > n - r) r = n - r;
  long long int ans = 1;
  int i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
long long int nCrModpDP(long long int n, long long int r, long long int p) {
  long long int C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p;
  }
  return C[r];
}
long long int ncrmod(long long int n, long long int r, long long int p) {
  if (r == 0) return 1;
  long long int ni = n % p, ri = r % p;
  return (ncrmod(n / p, r / p, p) * nCrModpDP(ni, ri, p)) % p;
}
long long int modInverse(long long int a, long long int m) {
  long long int m0 = m;
  long long int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int main() {
  int t;
  string str;
  cin >> t;
  while (t--) {
    map<pair<pair<int, int>, pair<int, int> >, int> vec;
    cin >> str;
    int x = 0, y = 0;
    long long int sum = 0;
    for (int i = 0; i < str.length(); i++) {
      if (str[i] == 'N') {
        y += 1;
        if (vec[{{x, y}, {x, y - 1}}] == 0)
          sum += 5;
        else
          sum += 1;
        vec[{{x, y - 1}, {x, y}}] = 1;
        vec[{{x, y}, {x, y - 1}}] = 1;
      } else if (str[i] == 'E') {
        x += 1;
        if (vec[{{x, y}, {x - 1, y}}] == 0)
          sum += 5;
        else
          sum += 1;
        vec[{{x - 1, y}, {x, y}}] = 1;
        vec[{{x, y}, {x - 1, y}}] = 1;
      } else if (str[i] == 'W') {
        x -= 1;
        if (vec[{{x, y}, {x + 1, y}}] == 0)
          sum += 5;
        else
          sum += 1;
        vec[{{x + 1, y}, {x, y}}] = 1;
        vec[{{x, y}, {x + 1, y}}] = 1;
      } else if (str[i] == 'S') {
        y -= 1;
        if (vec[{{x, y}, {x, y + 1}}] == 0)
          sum += 5;
        else
          sum += 1;
        vec[{{x, y + 1}, {x, y}}] = 1;
        vec[{{x, y}, {x, y + 1}}] = 1;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
