A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node may be supplied with an amount s(u) \geq 0 of power, may produce an amount 0 \leq p(u) \leq p_{\text{max}}(u) of power, may consume an amount 0 \leq c(u) \leq \min(s(u), c_{\text{max}}(u)) of power, and may deliver an amount d(u) = s(u) + p(u) - c(u) of power. The following restrictions apply: c(u) = 0 for any power station, p(u) = 0 for any consumer, and p(u) = c(u) = 0 for any dispatcher. There is at most one power transport line from a node to a node in the net; it transports an amount 0 \leq l(u, v) \leq l_{\text{max}}(u, v) of power delivered by to . Let Con = \sum_u c(u) be the power consumed in the net. The problem is to compute the maximum value of .

An example is in figure. The label of power station shows that p(u) = x and p_{\text{max}}(u) = y. The label of consumer shows that c(u) = x and c_{\text{max}}(u) = y. The label of power transport line shows that l(u, v) = x and l_{\text{max}}(u, v) = y. The power consumed is Con = 6. Notice that there are other possible states of the network but the value of cannot exceed .
There are several data sets in the input text file. Each data set encodes a power network. It starts with four integers: 0 \leq n \leq 100 (nodes), 0 \leq n_p \leq n (power stations), 0 \leq n_c \leq n (consumers), and 0 \leq m \leq n^2 (power transport lines). Follow data triplets (u, v)z, where and are node identifiers (starting from ) and 0 \leq z \leq 1000 is the value of l_{\text{max}}(u, v). Follow n_p doublets , where is the identifier of a power station and 0 \leq z \leq 10000 is the value of p_{\text{max}}(u). The data set ends with n_c doublets , where is the identifier of a consumer and 0 \leq z \leq 10000 is the value of c_{\text{max}}(u). All input numbers are integers. Except the (u, v)z triplets and the doublets, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and are correct.
For each data set from the input, the program prints on the standard output the maximum amount of power that can be consumed in the corresponding network. Each result has an integral value and is printed from the beginning of a separate line.
Example 1