#P1383F. Special Edges

Special Edges

No submission language available for this problem.

Description

Koa the Koala has a directed graph GG with nn nodes and mm edges. Each edge has a capacity associated with it. Exactly kk edges of the graph, numbered from 11 to kk, are special, such edges initially have a capacity equal to 00.

Koa asks you qq queries. In each query she gives you kk integers w1,w2,,wkw_1, w_2, \ldots, w_k. This means that capacity of the ii-th special edge becomes wiw_i (and other capacities remain the same).

Koa wonders: what is the maximum flow that goes from node 11 to node nn after each such query?

Help her!

The first line of the input contains four integers nn, mm, kk, qq (2n1042 \le n \le 10^4, 1m1041 \le m \le 10^4, 1kmin(10,m)1 \le k \le \min(10, m), 1q21051 \le q \le 2 \cdot 10^5) — the number of nodes, the number of edges, the number of special edges and the number of queries.

Each of the next mm lines contains three integers uu, vv, ww (1u,vn1 \le u, v \le n; 0w250 \le w \le 25) — the description of a directed edge from node uu to node vv with capacity ww.

Edges are numbered starting from 11 in the same order they are listed in the input. The first kk edges are the special edges. It is guaranteed that wi=0w_i = 0 for all ii with 1ik1 \le i \le k.

Each of the next qq lines contains kk integers w1,w2,,wkw_1, w_2, \ldots, w_k (0wi250 \le w_i \le 25)  — the description of the query. wiw_i denotes the capacity of ii-th edge.

For the ii-th query, print one integer resires_i  — the maximum flow that can be obtained from node 11 to node nn given the ii-th query's special edge weights.

Input

The first line of the input contains four integers nn, mm, kk, qq (2n1042 \le n \le 10^4, 1m1041 \le m \le 10^4, 1kmin(10,m)1 \le k \le \min(10, m), 1q21051 \le q \le 2 \cdot 10^5) — the number of nodes, the number of edges, the number of special edges and the number of queries.

Each of the next mm lines contains three integers uu, vv, ww (1u,vn1 \le u, v \le n; 0w250 \le w \le 25) — the description of a directed edge from node uu to node vv with capacity ww.

Edges are numbered starting from 11 in the same order they are listed in the input. The first kk edges are the special edges. It is guaranteed that wi=0w_i = 0 for all ii with 1ik1 \le i \le k.

Each of the next qq lines contains kk integers w1,w2,,wkw_1, w_2, \ldots, w_k (0wi250 \le w_i \le 25)  — the description of the query. wiw_i denotes the capacity of ii-th edge.

Output

For the ii-th query, print one integer resires_i  — the maximum flow that can be obtained from node 11 to node nn given the ii-th query's special edge weights.

Samples

Sample Input 1

2 1 1 3
1 2 0
0
1
2

Sample Output 1

0
1
2

Sample Input 2

4 4 2 5
1 2 0
2 3 0
2 4 5
3 4 2
0 0
1 10
10 0
7 1
7 2

Sample Output 2

0
1
5
6
7

Note

For the second sample, the following images correspond to the first two queries (from left to right respectively). For each edge there is a pair flow/capacity denoting flow pushed through the edge and edge's capacity. The special edges are colored in red.

As you can see in first query maximum flow from node 11 to node 44 equals 00 and in second query equals 11.