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;
long long int power(long long int x, long long int y, long long int p) {
  long long int 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;
}
bool sortinrev(const pair<vector<int>, int>& a,
               const pair<vector<int>, int>& b) {
  if (a.first == b.first) return b.second > a.second;
  return a.first > b.first;
}
void DFS(vector<int> adj[], vector<bool>& visited, int u, int n,
         vector<int>& vi) {
  visited[u] = true;
  vi.push_back(u);
  for (int i = 0; i < adj[u].size(); i++) {
    if (visited[adj[u][i]] == false) {
      (DFS(adj, visited, adj[u][i], n, vi));
    }
  }
}
void run(vector<int> v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
long long int fact(long long int n) {
  long long int f = 1;
  for (int i = 1; i <= n; i++) {
    f *= i;
  }
  return f;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long int a = 0, b = 0, sumu = 0, ans = 0;
    map<pair<long long int, long long int>, long long int> a1;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'N') {
        sumu += 10000000000;
        if (a1.find({sumu, sumu - 10000000000}) == a1.end())
          ans += 5;
        else
          ans += 1;
        a1[{sumu, sumu - 10000000000}]++;
        a1[{sumu - 10000000000, sumu}]++;
      } else if (s[i] == 'S') {
        sumu -= 10000000000;
        if (a1.find({sumu, sumu + 10000000000}) == a1.end())
          ans += 5;
        else
          ans += 1;
        a1[{sumu, sumu + 10000000000}]++;
        a1[{sumu + 10000000000, sumu}]++;
      } else if (s[i] == 'E') {
        sumu += 1;
        if (a1.find({sumu, sumu - 1}) == a1.end())
          ans += 5;
        else
          ans += 1;
        a1[{sumu, sumu - 1}]++;
        a1[{sumu - 1, sumu}]++;
      } else {
        sumu -= 1;
        if (a1.find({sumu, sumu + 1}) == a1.end())
          ans += 5;
        else
          ans += 1;
        a1[{sumu, sumu + 1}]++;
        a1[{sumu + 1, sumu}]++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
