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;
int z, n, m, a, b, q, wyn, nr, d;
set<pair<int, int> > sk, sz;
vector<pair<int, int> > vk, vz;
vector<int> tp;
vector<pair<int, int> > gendrz(int nn) {
  vector<pair<int, int> > pra = {{1, 10}, {3, 1}};
  vector<int> rn;
  for (int i = 0; i < (int)pra.size(); ++i) {
    for (int j = 0; j < pra[i].second; ++j) {
      rn.push_back(pra[i].first);
    }
  }
  int zak = rn.size();
  vector<pair<int, int> > vwyn;
  queue<int> qw;
  qw.push(1);
  int x, y;
  int nas = 2;
  while (!qw.empty()) {
    x = qw.front();
    qw.pop();
    y = rn[rand() % zak];
    for (int i = 0; i < y; ++i) {
      if (nas <= nn) {
        qw.push(nas);
        vwyn.push_back({x, nas});
        ++nas;
      } else {
        break;
      }
    }
  }
  return vwyn;
}
int main() {
  int tt;
  cin >> tt;
  set<pair<pair<int, int>, pair<int, int> > > ss;
  for (int ii = 0; ii < tt; ++ii) {
    ss.clear();
    pair<int, int> prew = {0, 0};
    pair<int, int> cure = prew;
    string s;
    cin >> s;
    int wyn = 0;
    for (int i = 0; i < (int)s.length(); ++i) {
      cure = prew;
      if (s[i] == 'N') {
        cure.first++;
      } else if (s[i] == 'S') {
        cure.first--;
      } else if (s[i] == 'W') {
        cure.second++;
      } else {
        cure.second--;
      }
      if (prew < cure) {
        if (ss.find({prew, cure}) != ss.end()) {
          wyn += 1;
        } else {
          wyn += 5;
        }
        ss.insert({prew, cure});
      } else {
        if (ss.find({cure, prew}) != ss.end()) {
          wyn += 1;
        } else {
          wyn += 5;
        }
        ss.insert({cure, prew});
      }
      prew = cure;
    }
    cout << wyn << endl;
  }
  return 0;
  scanf("%d", &z);
  srand(z);
  n = 10;
  d = 10;
  d = min((long long)d, ((n - 1) * (long long)(n - 2)) / 2);
  m = n - 1 + d;
  q = 10;
  q = min((long long)q, (n * (long long)(n - 1)) / 2);
  vk = gendrz(n);
  for (int i = 0; i < (int)vk.size(); ++i) {
    sk.insert(vk[i]);
  }
  sk.insert({0, 0});
  for (int i = 0; i < d; ++i) {
    a = 0;
    b = 0;
    while (sk.find({a, b}) != sk.end()) {
      a = rand() % n + 1;
      b = rand() % n + 1;
      if (a > b) {
        swap(a, b);
      }
      if (a == b) {
        a = 0;
        b = 0;
      }
    }
    sk.insert({a, b});
    vk.push_back({a, b});
  }
  sz.insert({0, 0});
  for (int i = 0; i < q; ++i) {
    a = 0;
    b = 0;
    while (sz.find({a, b}) != sz.end()) {
      a = rand() % n + 1;
      b = rand() % n + 1;
      if (a > b) {
        swap(a, b);
      }
      if (a == b) {
        a = 0;
        b = 0;
      }
    }
    sz.insert({a, b});
    vz.push_back({a, b});
  }
  for (int i = 1; i <= n; ++i) {
    tp.push_back(i);
  }
  random_shuffle(tp.begin(), tp.end());
  for (int i = 0; i < m; ++i) {
    vk[i].first = tp[vk[i].first - 1];
    vk[i].second = tp[vk[i].second - 1];
    if (rand() & 1) {
      swap(vk[i].first, vk[i].second);
    }
  }
  random_shuffle(vk.begin(), vk.end());
  for (int i = 0; i < q; ++i) {
    vz[i].first = tp[vz[i].first - 1];
    vz[i].second = tp[vz[i].second - 1];
    if (rand() & 1) {
      swap(vz[i].first, vz[i].second);
    }
  }
  random_shuffle(vz.begin(), vz.end());
  printf("%d %d\n", n, m);
  for (int i = 0; i < (int)vk.size(); ++i) {
    printf("%d %d\n", vk[i].first, vk[i].second);
  }
  printf("%d\n", q);
  for (int i = 0; i < q; ++i) {
    printf("%d %d\n", vz[i].first, vz[i].second);
  }
  return 0;
}
