Under construction

Still being built. Things may change

1 Day Passport

Time limit8sMemory limit512 MB

Summary
Find the cheapest combination of unlimited-ride company passes and per-ride fares to travel from station S to T within H hours, where every train departs only on the hour.
Level

Hard8 of 10

Topics
Shortest path, Bit manipulation, Dynamic programming, Graph
Solved
No attempts yet

Problem

D, a university student living in some country, is a huge fan of the national guitarist A and plans to attend a live concert held downtown this summer. But since D lives in a remote region, he was very worried about the travel cost. Then he learned about the "1Day Passport" sold cheaply by an organization called JAG.

JAG (Journey Administrative Group) oversees several railway companies in D's country. JAG has many stations nationwide and maintains lines connecting them. Each line is managed by one of the companies belonging to JAG and connects two stations in both directions with no intermediate station. Each line also has a fixed fare and travel time (the same in either direction). JAG's timetable is simple: trains arrive at and depart from stations at 0 minutes past every hour. Each JAG station is designed very efficiently, so the time to transfer between lines can be ignored. The travel cost is the simple sum of the fares.

The 1Day Passport is an unlimited-ride pass that JAG started selling to escape its recent financial trouble. JAG sells several kinds of 1Day Passports. Each passport can be bought at the price JAG sets. A passport also lists some company names belonging to JAG, and all lines managed by those companies can be ridden unlimited times for one day (at no extra charge). Any number of passports can be bought, and multiple passports can be used together. However, when passing through a line managed by a company not written on any passport, its fare must be paid as usual.

D wants to use 1Day Passports well to reach the concert venue while spending as little money as possible. He also dislikes spending extra money on lodging, so he wants to reach the venue within HH hours, which is one day in this country. But he is not good at calculation, so he asks you, his university friend who is good at programming, for help. For D's sake, write the following program.

Given JAG's line information and 1Day Passport information, write a program to find the minimum cost (minimum of the sum of passport prices and fares) to travel from D's nearest station to the concert venue's nearest station within HH hours. If he cannot arrive within HH hours, or there is no route to the concert venue, output -1.

Input

The input consists of multiple data sets, and the number of data sets in one input is at most 150. The format of each data set is as follows.

NN MM HH KK

a1a_1 b1b_1 c1c_1 h1h_1 r1r_1

...

aMa_M bMb_M cMc_M hMh_M rMr_M

SS TT

PP

l1l_1 d1d_1 k1,1k_{1,1} ... k1,l1k_{1,l_1}

...

lPl_P dPd_P kP,1k_{P,1} ... kP,lPk_{P,l_P}

All input values are integers.

First, JAG's line information is given. NN (2≤N≤1002 \le N \le 100) is the number of stations, MM (1≤M≤5001 \le M \le 500) is the number of lines, HH (1≤H≤241 \le H \le 24) is the hours in one day, and KK (1≤K≤81 \le K \le 8) is the number of companies belonging to JAG. Stations are numbered 1,2,…,N1, 2, \ldots, N. Companies are numbered 1,2,…,K1, 2, \ldots, K. Then MM lines of line information follow. aia_i and bib_i (1≤ai<bi≤N1 \le a_i < b_i \le N) are the two stations connected by the ii-th line. cic_i (1≤ci≤10,0001 \le c_i \le 10{,}000) is the fare of the ii-th line, hih_i (1≤hi≤H1 \le h_i \le H) is the travel time of the line, and rir_i (1≤ri≤K1 \le r_i \le K) is the company managing the line. There are no two or more lines connecting the same pair of stations.

The next line gives SS, D's nearest station, and TT, the station nearest to A's concert venue (1≤S,T≤N1 \le S, T \le N). SS and TT are different values.

Next, 1Day Passport information is given. PP (0≤P≤2K−10 \le P \le 2^K - 1) is the number of kinds of 1Day Passports. Then PP lines of 1Day Passport information follow. ljl_j (1≤lj≤K1 \le l_j \le K) and djd_j (1≤dj≤10,0001 \le d_j \le 10{,}000) are the number of companies written on the jj-th 1Day Passport and the passport price, respectively. On the same line, the ljl_j company numbers kj,1,kj,2,…,kj,ljk_{j, 1}, k_{j, 2}, \ldots, k_{j, l_j} written on the jj-th passport are given (1≤kj,1<kj,2<⋯<kj,lj≤K1 \le k_{j, 1} < k_{j, 2} < \cdots < k_{j, l_j} \le K). No two 1Day Passports with the same set of companies are given.

The end of the input is indicated by a line with N=M=H=K=0N=M=H=K=0. This data set must not be processed.

Output

For each data set, output the result on one line. That is, if a route exists from D's nearest station to the station nearest to the concert venue and he can arrive within HH hours, output the minimum fare needed; otherwise output -1.

Examples1

  1. Example 1

    Input
    3 3 3 2
    1 2 3 1 1
    1 3 8 1 1
    2 3 3 2 2
    1 3
    0
    3 3 2 2
    1 2 3 1 1
    1 3 8 1 1
    2 3 3 2 2
    1 3
    0
    6 4 3 2
    1 2 3 1 1
    1 3 8 1 1
    4 6 3 2 2
    5 6 7 2 2
    1 6
    0
    3 3 3 2
    1 2 3 1 1
    1 3 8 1 1
    2 3 3 2 2
    1 3
    2
    2 6 1 2
    1 2 2
    3 3 2 2
    1 2 3 1 1
    1 3 8 1 1
    2 3 3 2 2
    1 3
    2
    2 6 1 2
    1 2 2
    3 2 2 2
    1 2 3 1 1
    2 3 3 2 2
    1 3
    2
    2 6 1 2
    1 2 2
    5 4 20 4
    2 4 100 5 1
    1 4 100 5 3
    1 5 100 5 4
    3 5 100 5 2
    3 2
    3
    2 80 1 2
    2 60 1 3
    2 40 2 3
    0 0 0 0
    
    Expected output
    6
    8
    -1
    5
    6
    -1
    200