Vote-Value Disparity 1

No attempts yetTime limit1sMemory limit128 MB

Problem

A national election will be held in the JOI kingdom. The kingdom has NN provinces.

The map is an H×WH \times W grid. Each cell connects to neighbors by sharing a side. The grid is partitioned into NN connected provinces. Province ii has PiP_i voters.

You must divide the provinces into KK electoral districts to elect KK representatives. Each district contains at least one province, and the cells in a district form a connected region. Cells connect only through shared sides, not shared corners.

The weight of a single vote in a district is 1/(number of voters in that district)1 / \text{(number of voters in that district)}. The vote-value disparity is the maximum such weight divided by the minimum. Minimize this disparity.

Input

The first line contains HH, WW, NN, and KK.

Each of the next HH lines has WW integers SijS_{ij}, the province id of each cell.

Each of the next NN lines has PiP_i, the number of voters in province ii.

Output

Print NN lines. Line ii is the district number (11 to KK) for province ii.

Constraints

  • 1H2001 \le H \le 200
  • 1W2001 \le W \le 200
  • 1N100001 \le N \le 10\,000
  • 1KN1 \le K \le N
  • 1Pi1000001 \le P_i \le 100\,000
  • Each province forms a connected region on the grid.