A new trade empire is rising in Berland. Bulmart, an emerging trade giant, decided to dominate the market of ... shovels! And now almost every city in Berland has a Bulmart store, and some cities even have several of them! The only problem is, at the moment sales are ... let's say a little below estimates. Some people even say that shovels retail market is too small for such a big company to make a profit. But the company management believes in the future of that market and seeks new ways to increase income.
There are
n cities in Berland connected with
m bi-directional roads. All roads have equal lengths. It can happen that it is impossible to reach a city from another city using only roads. There is no road which connects a city to itself. Any pair of cities can be connected by at most one road.
There are
w Bulmart stores in Berland. Each of them is described by three numbers:
- ci − the number of city where the i-th store is located (a city can have no stores at all or have several of them),
- ki − the number of shovels in the i-th store,
- pi − the price of a single shovel in the i-th store (in burles).
The latest idea of the Bulmart management is to create a program which will help customers get shovels as fast as possible for affordable budget. Formally, the program has to find the minimum amount of time needed to deliver
rj shovels to the customer in the city
gj for the total cost of no more than
aj burles. The delivery time between any two adjacent cities is equal to
1. If shovels are delivered from several cities, the delivery time is equal to the arrival time of the last package. The delivery itself is free of charge.
The program needs to find answers to
q such queries. Each query has to be processed independently from others, i.e. a query does not change number of shovels in stores for the next queries.
Output
Output
q lines. On the
j-th line, print an answer for the
j-th query − the minimum amount of time needed to deliver
rj shovels to the customer in city
gj spending no more than
aj burles. Print
-1 if there is no solution for the
j-th query.