Problem: Mark and his crew are sailing across the sea of Aeolus (in Greek mythology Aeolus was the keeper of the winds). They have the map which represents the NxM matrix with land and sea fields and they want to get to the port (the port is considered as sea field). They are in a hurry because the wind there is very strong and changeable and they have the food for only K days on the sea (that is the maximum that they can carry on the ship). John, the guy from Mark's crew, knows how to predict the direction of the wind on daily basis for W days which is enough time for them to reach the port or to run out of the food. Mark can move the ship in four directions (north, east, south, west) by one field for one day, but he can also stay in the same place. Wind can blow in four directions (north, east, south, west) or just not blow that day. The wind is so strong at the sea of Aeolus that it moves the ship for one whole field in the direction which it blows at. The ship's resulting movement is the sum of the ship's action and wind from that day. Mark must be careful in order to keep the ship on the sea, the resulting movement must end on the sea field and there must be a 4-connected path through the sea from the starting field. A 4-connected path is a path where you can go from one cell to another only if they share a side.

For example in the following image, the ship can't move to the port as there is no 4-connected path through the sea. 

<image>

In the next image, the ship can move to the port as there is a 4-connected path through the sea as shown with the red arrow. Furthermore, the ship can move to the port in one move if one of the following happens. Wind is blowing east and Mark moves the ship north, or wind is blowing north and Mark moves the ship east. In either of these scenarios the ship will end up in the port in one move. 

<image>

Mark must also keep the ship on the map because he doesn't know what is outside. Lucky for Mark and his crew, there are T fish shops at the sea where they can replenish their food supplies to the maximum, but each shop is working on only one day. That means that Mark and his crew must be at the shop's position on the exact working day in order to replenish their food supplies. Help Mark to find the minimum of days that he and his crew need to reach the port or print -1 if that is impossible with the food supplies that they have.

Input

First line contains two integer numbers N and M (1 ≤ N, M ≤ 200) - representing the number of rows and number of columns of the map. 

Second line contains three integers, K (0 ≤ K ≤ 200) which is the number of days with the available food supplies, T (0 ≤ T ≤ 20) which is the number of fields with additional food supplies and W (0 ≤ W ≤ 10^6) which is the number of days with wind information.

Next is the NxM char matrix filled with the values of 'L', 'S', 'P' or 'M'. 'L' is for the land and 'S' is for the sea parts. 'P' is for the port field and 'M' is the starting field for the ship.

Next line contains W chars with the wind direction information for every day. The possible inputs are 'N' - north, 'S' - south, 'E' - east, 'W' - west and 'C' - no wind. If Mark's crew can reach the port, it is guaranteed that they will not need more than W days to reach it.

In the end there are T lines with the food supplies positions. Each line contains three integers, Y_i and X_i (0 ≤ Y_i < N, 0 ≤ X_i < M) representing the coordinates (Y is row number and X is column number) of the food supply and F_i (0 ≤ F_i ≤ 10^6) representing the number of days from the starting day on which the food supply is available.

Output

One integer number representing the minimal days to reach the port or -1 if that is impossible.

Examples

Input


3 3
5 2 15
M S S
S S S
S S P
S W N N N N N N N N N N N N N
2 1 0
1 2 0


Output


-1

Input


3 3
5 2 15
M S S
S S S
S S P
S E N N N N N N N N N N N N N
2 1 0
1 2 0


Output


2

Input


5 5
4 1 15
M S S S S
S S S S L
S S S L L
S S S S S
S S S S P
C C C C S S E E C C C C C C C
0 1 4


Output


8

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC target("avx,avx2")
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
char readc() {
  char c;
  while ((c = getchar()) < '-')
    ;
  return c;
}
int read() {
  char c;
  while ((c = getchar()) < '-')
    ;
  if (c == '-') {
    int x = (c = getchar()) - '0';
    while ((c = getchar()) >= '0') x = x * 10 + c - '0';
    return -x;
  }
  int x = c - '0';
  while ((c = getchar()) >= '0') x = x * 10 + c - '0';
  return x;
}
const int N = 200 + 5, T = 20 + 5, W = 1e6 + 5;
const char char_dir[] = "NSEWC";
const int dx[] = {-1, 1, 0, 0, 0}, dy[] = {0, 0, 1, -1, 0};
int char_dy_dir[128];
char s[W];
int nex[W][5];
bool valid[N][N];
int g[N][N];
struct Supply {
  int x, y, t, mn;
} supply[T];
int main() {
  int n, m;
  cin >> n >> m;
  int k, t, w;
  cin >> k >> t >> w;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char c = readc();
      if (c == 'L') continue;
      valid[i][j] = 1;
      if (c == 'M')
        supply[0] = {i, j, 0};
      else if (c == 'P')
        supply[t + 1] = {i, j, w};
    }
  }
  for (int i = 1; i <= w; ++i) s[i] = readc();
  for (int i = 0; i <= 4; ++i) char_dy_dir[(int)char_dir[i]] = i;
  for (int j = 0; j <= 4; ++j) nex[w + 1][j] = w + 1;
  for (int i = w; i >= 1; --i) {
    for (int j = 0; j <= 4; ++j) nex[i][j] = nex[i + 1][j];
    nex[i][char_dy_dir[(int)s[i]]] = i;
  }
  for (int i = 1; i <= t; ++i) {
    supply[i].x = read() + 1;
    supply[i].y = read() + 1;
    supply[i].t = read();
  }
  sort(supply + 1, supply + t + 1,
       [&](const Supply &a, const Supply &b) { return a.t < b.t; });
  while (t && supply[t].t > w) {
    supply[t] = supply[t + 1];
    --t;
  }
  for (int i = 1; i <= t + 1; ++i) supply[i].mn = supply[i].t + 1;
  for (int i = 0; i <= t; ++i)
    if (supply[i].mn <= supply[i].t && valid[supply[i].x][supply[i].y]) {
      int limit = min(w + 1, supply[i].t + k + 1);
      for (int x = 1; x <= n; ++x)
        for (int y = 1; y <= m; ++y) g[x][y] = limit;
      priority_queue<int> heap;
      auto push = [&](int x, int y, int t) {
        if (g[x][y] > t) {
          g[x][y] = t;
          heap.push(-(t * N * N + x * N + y));
        }
      };
      push(supply[i].x, supply[i].y, supply[i].t);
      while (!heap.empty()) {
        int t = -heap.top();
        heap.pop();
        int y = t % N;
        t /= N;
        int x = t % N;
        t /= N;
        if (t != g[x][y]) continue;
        for (int dir = 0; dir <= 4; ++dir) {
          int t1 = nex[t + 1][dir];
          if (t1 >= limit) continue;
          int x1 = x + dx[dir], y1 = y + dy[dir];
          if (valid[x1][y1]) {
            for (int dir1 = 0; dir1 <= 4; ++dir1) {
              int x2 = x1 + dx[dir1], y2 = y1 + dy[dir1];
              if (valid[x2][y2]) push(x2, y2, t1);
            }
          } else {
            for (int dir1 = 0; dir1 <= 4; ++dir1) {
              x1 = x + dx[dir1];
              y1 = y + dy[dir1];
              if (valid[x1][y1]) {
                int x2 = x1 + dx[dir], y2 = y1 + dy[dir];
                if (valid[x2][y2]) push(x2, y2, t1);
              }
            }
          }
        }
      }
      for (int j = i + 1; j <= t + 1; ++j)
        if (g[supply[j].x][supply[j].y] < limit)
          chmin(supply[j].mn, g[supply[j].x][supply[j].y]);
    }
  if (supply[t + 1].mn > w)
    puts("-1");
  else
    printf("%d\n", supply[t + 1].mn);
}