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 R rows and C columns, as well as the number N - 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 Q 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 i and column j (1≤i≤R, 1≤j≤C), you have three numbers U_i,j, V_i,j and W_i,j, which means that in the field (i,j), there is an edge between node U_i,j and V_i,j, with weight W_i,j. After that you have Q queries. Each query is described by four numbers X_1,Y_1,X_2,Y_2 (1≤X_1≤X_2≤R, 1≤Y_1≤Y_2≤C), where (X_1,Y_1) is the upper left corner of the given submatrix, and (X_2,Y_2) is the bottom right corner of the submatrix. For each query consider graph with all N 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" (quotes for clarity). For each query, condition: 32≤Y_2−Y_1+1X_2−X_1+1≤23 holds.
In first line, there are numbers N, R, C and Q (2≤N≤40, 1≤R,C≤250, 1≤Q≤200000).
R rows follow and in each of them 3C numbers. In ith row the numbers are: U_i,1, V_i,1, W_i,1, U_i,2, V_i,2, W_i,2,...,U_i,C, V_i,C, W_i,C (0≤W_i,j≤65535, for each 1≤j≤C).
Q rows follow and in each of them 4 numbers - X_1, Y_1, X_2 and Y_2.
Print Q rows, in ith row answer to the ith query.