Edit

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

You are given two weighted rooted trees. For each vertex, the children are ordered. You can assume they are arranged from left to right. You have four elementary operations: growing, expansion, contraction, and relabeling.

  1. Growing: For a vertex xx, let the children list be y_1,y_2,,y_my\_1, y\_2, \ldots, y\_m. You can add a new vertex zz, add an edge between xx and zz, and insert the vertex zz to the kk-th position in the children list. The children list of xx becomes y_1,y_2,,y_k1,z,y_k,y_k+1,,y_my\_1, y\_2, \ldots, y\_{k-1}, z, y\_k, y\_{k+1}, \ldots, y\_m. The cost of this operation is c_1c\_1 times the weight of the new edge (x,z)(x, z).
  2. Expansion: For a vertex xx, let the children list be y_1,y_2,,y_my\_1, y\_2, \ldots, y\_m. You can choose an interval \[l,r]\[l, r] (1lrm1 \leq l \leq r \leq m). Add a new vertex zz as the parent of vertices y_l,y_l+1,,y_ry\_l, y\_{l+1}, \ldots, y\_r, and an edge between xx and zz. The children list of xx becomes y_1,y_2,,y_l1,z,y_r+1,,y_my\_1, y\_2, \ldots, y\_{l-1}, z, y\_{r+1}, \ldots, y\_m. The children list of zz becomes y_l,y_l+1,,y_ry\_l, y\_{l+1}, \ldots, y\_r. For all lirl \leq i \leq r, the weight of the edge (z,y_i)(z, y\_i) is the same as the edge (x,y_i)(x, y\_i) in the original tree. The cost of this operation is c_1c\_1 times the weight of the new edge (x,z)(x, z).
  3. Contraction: For a vertex xx, let the children list be y_1,y_2,,y_my\_1, y\_2, \ldots, y\_m. You can choose one of its children y_ky\_k. Let the children list of y_ky\_k be z_1,z_2,,z_pz\_1, z\_2, \ldots, z\_p. You can contract the edge (x,y_k)(x, y\_k). The vertex y_ky\_k is removed after this operation. And the children list of xx becomes y_1,y_2,,y_k1,z_1,z_2,,z_p,y_k+1,,y_my\_1, y\_2, \ldots, y\_{k-1}, z\_1, z\_2, \ldots, z\_p, y\_{k+1}, \ldots, y\_m. For all 1ip1 \leq i \leq p, the weight of the edge (x,z_i)(x, z\_i) is the same as the edge (y_k,z_i)(y\_k, z\_i) in the original tree. The cost of this operation is c_2c\_2 times the weight of the edge (x,y_k)(x, y\_k) in the original tree.
  4. Relabeling: For a vertex xx and one of its children yy, change the weight of edge (x,y)(x, y) from w_1w\_1 to w_2w\_2. The cost of this operation is c_3w_1w_2c\_3 \cdot |w\_1 - w\_2|.

There are also some special rules:

  • You can not relabel an edge which is the (x,z)(x, z) edge added by growing or expansion operation.
  • You can not contract an edge which was relabeled.

You want to perform these operations, and change the first tree into the second tree. Output the minimum cost of doing so.

Two trees are considered the same if and only if there is a bijection from the vertices of the first tree to the vertices of the second tree that preserves the root and the order of children, and the weights of corresponding edges are the same.

입력

The first line contains three integers c_1c\_1, c_2c\_2, and c_3c\_3 (1c_1,c_2,c_31061 \leq c\_1, c\_2, c\_3 \leq 10^6) indicating the cost of growing (or expansion), contraction, and relabeling, respectively.

Next, the two trees are given.

For each tree, the first line contains an integer nn indicating the number of vertices. In the following nn lines, each line starts an with integer kk indicating the number of children, followed by 2k2 k integers c_1,w_1,,c_k,w_kc\_1, w\_1, \ldots, c\_k, w\_k (0c_i1060 \leq c\_i \leq 10^6) indicating the children list and the weights of edges to children.

The size of the first tree will not be greater than 5050. The size of the second tree will not be greater than 20002000.

출력

Output the answer.