The kingdom of Quadradonia is divided into provinces arranged in a grid of R rows and C columns. The roads between them are dangerous, so nobody travels alone. Every trip goes by escorted carriage, and the carriages belong to the Interprovincial Communication and Peregrination Company (ICPC).
The company charges like this. In the province in row i and column j you rent a carriage for a cost of Vij. That carriage takes you to any province at most Rij rows away from row i and at most Cij columns away from column j, that is, to the province in row i′ and column j′ whenever ∣i−i′∣≤Rij and ∣j−j′∣≤Cij. The price is flat: it depends on the province where you rent, not on where you get off.
You want to visit N provinces p1,p2,…,pN in that order. Your budget is small, so for every leg of the trip you want the cheapest way to make it. A leg may pass through any number of intermediate provinces, and you pay the rental cost of every province where you board a carriage.
The first line contains three integers R, C and N (1≤R,C≤500, 2≤N≤5), the number of rows, the number of columns and the number of provinces you want to visit. Rows are numbered from 1 to R and columns from 1 to C.
The next 3×R lines form three groups of R lines, each line holding C integers. The j-th number on the i-th line of the first group is Vij (1≤Vij≤1000). The second group gives Rij (0≤Rij≤R) in the same layout, and the third group gives Cij (0≤Cij≤C).
The last N lines describe p1,p2,…,pN in visiting order. The k-th of them contains two integers Ik and Jk (1≤Ik≤R, 1≤Jk≤C), meaning that pk is the province in row Ik and column Jk.
Print one line with N−1 integers separated by single spaces. For k=1,2,…,N−1, the k-th number is the minimum total rental cost of going from pk to pk+1 with the escorted carriage system, or −1 if that leg is impossible. If pk and pk+1 are the same province the cost is 0.