A new candy factory opens in pku-town. The factory import M machines to produce high quality candies. These machines are numbered from 1 to M.
There are N candies need to be produced. These candies are also numbered from 1 to N. For each candy i , it can be produced in any machine j. It also has a producing time(s
i,t
i) , meaning that candy i must start producing at time s
i and will finish at t
i. Otherwise if the start time is p
i(s
i < p
i < t
i) then candy will still finish at t
i but need additional K*(p
i - s
i) cost. The candy can’t be produced if p
i is greater than or equal to t
i. Of course one machine can only produce at most one candy at a time and can’t stop once start producing.
On the other hand, at time 0 all the machines are in their initial state and need to be “set up” or changed before starting producing. To set up Machine j from its initial state to the state which is suitable for producing candiy i, the time required is C
ij and cost is D
ij. To change a machine from the state suitable for candy i
1 into the state suitable for candy i
2, time required is E
i1i2 and cost is F
i1i2.
As the manager of the factory you have to make a plan to produce all the N candies. While the sum of producing cost should be minimized.
There are multiple test cases.
For each case, the first line contains three integers N(1<=N<=100), M(1<=M<=100), K(1<=K<=100) . The meaning is described above.
Then N lines follow, each line contains 2 integers s
i and t
i(0 <= s
i < t
i <100000).
Then N lines follow, each line contains M integers, the j-th integer of the i-th line indicating C
ij(1<=C
ij<=100000) .
Then N lines follow, each line contains M integers, the j-th integer of the i-th line indicating D
ij(1<=D
ij<=100000) .
Then N lines follow, each line contains N integers, the i
2-th integer of the i
1-th line indicating E
i1i2(1<=E
i1j2<=100000) .
Then N lines follow, each line contains N integers, the i
2-th integer of the i
1-th line indicating F
i1i2(1 <= F
i1j2<=100000) .
Since the same candy will only be produced once, E
ii and F
ii are meaningless and will always be -1.
The input ends by N=0 M=0 K=0. Cases are separated with a blank line.
For each test case, if all of M candies can be produced, output the sum of minimum producing cost in a single line. Otherwise output -1.