UFO

No attempts yetTime limit5sMemory limit256 MB

Problem

Snakeland's security service damaged a hostile alien ship and forced it to land. The ship is built from unit cubes called compartments. Seen from above it covers a grid of NN rows and MM columns, and over the cell in row ii, column jj there is a stack of hi,jh_{i,j} compartments. Layers are numbered from 1 at the ground, so the cell in row ii, column jj holds a compartment on layer LL exactly when hi,jLh_{i,j} \ge L.

The compartments are made of a metal that only a laser cuts. Laser devices stand on all four sides of the ship, and each device fires beams perpendicular to its own side. A beam runs horizontally along one row or one column at one fixed layer.

Row 1 is the northmost row and column 1 is the westmost column. A beam fired from the west travels along its row from column 1 towards column MM, and a beam fired from the east travels from column MM towards column 1. A beam fired from the north travels along its column from row 1 towards row NN, and a beam fired from the south travels from row NN towards row 1.

A beam destroys the first RR compartments on its path. Looking at one cell at a time in the direction of travel, the beam destroys the compartment on the layer being shot whenever that cell's stack still reaches the layer, and it stops once it has destroyed RR of them. The compartments above a destroyed one drop by one layer, so destroying a compartment in a cell lowers that cell's stack by 1. When the beam leaves the ship before destroying RR compartments, it destroys fewer.

After KK shots the ship is bombed from the air. The bomb covers a grid-aligned square of PP rows and PP columns and destroys every compartment left over those P×PP \times P cells. Write a program that computes the largest number of compartments one bomb can destroy.

Input

The first line contains five integers NN, MM, RR, KK, PP (1N×M1061 \le N \times M \le 10^6, 1R101 \le R \le 10, 1K3×1051 \le K \le 3 \times 10^5, 1Pmin(N,M,10)1 \le P \le \min(N, M, 10)).

Each of the next NN lines contains MM integers. The jj-th integer on the ii-th of these lines is hi,jh_{i,j}, the number of compartments stacked over the cell in row ii, column jj (1hi,j1061 \le h_{i,j} \le 10^6).

Each of the next KK lines describes one shot with a letter and two integers. The letter is the side the beam comes from and is one of W, E, S, N. For W and E the first integer is a row number between 1 and NN; for N and S it is a column number between 1 and MM. The second integer is the layer being shot, between 1 and 10610^6. The shots are processed in the order given.

Output

Print one integer, the largest number of compartments left over any P×PP \times P block of cells after all KK shots.