MST Camera

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

문제

On a recent team contest your team was the best, and therefore won the best award. A camera. But it's not an ordinary camera, manufacturer of the camera, the famous "MST" company claims that this camera has unique capability. If you use it to picture some set of undirected edges of some graph, it is capable of calculating wheter it is possible to form a tree with these edges, and even better, if edges are weighted it is capable of finding a tree with minimum possible sum of weights of edges.

Your task is to check whether your camera works or not. You have a matrix with RR rows and CC columns, as well as the number NN - the number of nodes in the graph. In every field of the matrix, you have one undirected edge of the graph. You should answer on QQ queries, where each query is some submatrix of the original matrix. Answer to that query is the sum of weights of edges of minimum spanning tree, formed with edges in the given submatrix.

Formally, in field which is in row ii and column jj (1iR1 \leq i \leq R, 1jC1 \leq j \leq C), you have three numbers U_i,jU\_{i,j}, V_i,jV\_{i,j} and W_i,jW\_{i,j}, which means that in the field (i,j)(i,j), there is an edge between node U_i,jU\_{i,j} and V_i,jV\_{i,j}, with weight W_i,jW\_{i,j}. After that you have QQ queries.  Each query is described by four numbers X_1,Y_1,X_2,Y_2X\_{1},Y\_{1},X\_{2},Y\_{2} (1X_1X_2R1 \leq X\_{1} \leq X\_{2} \leq R, 1Y_1Y_2C1 \leq Y\_{1} \leq Y\_{2} \leq C), where (X_1,Y_1)(X\_{1},Y\_{1}) is the upper left corner of the given submatrix, and (X_2,Y_2)(X\_{2},Y\_{2}) is the bottom right corner of the submatrix. For each query consider graph with all NN nodes and edges from the given submatrix. If there exists minimum spanning tree, you should print the sum of weights of tree edges. If spanning tree doesn't exist, you should print "1-1" (quotes for clarity). For each query, condition: 23X_2X_1+1Y_2Y_1+132\frac{2}{3} \leq \frac{X\_{2}-X\_{1}+1}{Y\_{2}-Y\_{1}+1} \leq \frac{3}{2} holds.

입력

In first line, there are numbers NN, RR, CC and QQ (2N402 \leq N \leq 40, 1R,C2501 \leq R,C \leq 250, 1Q2000001 \leq Q \leq 200000).

RR rows follow and in each of them 3C3C numbers. In iith row the numbers are: U_i,1U\_{i,1}, V_i,1V\_{i,1}, W_i,1W\_{i,1}, U_i,2U\_{i,2}, V_i,2V\_{i,2}, W_i,2W\_{i,2},...,U_i,CU\_{i,C}, V_i,CV\_{i,C}, W_i,CW\_{i,C} (0W_i,j655350 \leq W\_{i,j} \leq 65535, for each 1jC1 \leq j \leq C).

QQ rows follow and in each of them 44 numbers - X_1X\_{1}, Y_1Y\_{1}, X_2X\_{2} and Y_2Y\_{2}.

출력

Print QQ rows, in iith row answer to the iith query.