402219: GYM100703 B Energy Saving
Description
During tea-drinking, Princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Prince in the Castle? Dragon smiled enigmatically and answered that it is a big secret. After a pause, Dragon added:
— We have a contract. A rental agreement. He always works all day long. He likes silence. Besides that, there are many more advantages of living here in the Castle. Say, it is easy to justify a missed call: a phone ring can't reach the other side of the Castle from where the phone has been left. So, the imprisonment is just a tale. Actually, he thinks about everything. He is smart. For instance, he started replacing incandescent lamps with energy-saving lamps in the whole Castle...
Prince chose a model of energy-saving lamps and started the replacement as described below. He numbered all rooms in the Castle and counted how many lamps in each room he needs to replace.
At the beginning of each month, Prince buys m energy-saving lamps and replaces lamps in rooms according to his list. He chooses the first room in his list, in which lamps are not replaced yet. If Prince has enough lamps to replace all lamps in the room, he replaces all ones and takes the room out from the list. If there are still some energy-saving lamps unused, he considers replacement in the next room, which is the first in his list. This repeats while he still has some energy-saving lamps and number of lamps to replace in the next room is not greater than number of energy-saving lamps which Prince has in stock. Otherwise he postpones the replacement and saves the rest of energy-saving lamps for the next month.
As soon as all the work is done, he ceases buying new lamps. They are very high quality and have a very long life cycle.
Your task is for a given number of month and descriptions of rooms to compute in how many rooms the old lamps will be replaced with energy-saving ones and how many energy-saving lamps will remain by the end of each month.
InputThe first line contains integers n and m (1 ≤ n ≤ 1000, 1 ≤ m ≤ 100) — the number of rooms in the Castle and the number of energy-saving lamps, which Prince buys monthly.
The second line contains n integers k1, k2, ..., kn (1 ≤ kj ≤ 1000, j = 1, 2, ..., n) — the number of lamps in the rooms of the Castle. The number in position #j is the number of lamps in #jth room. Room numbers are given in accordance with Prince's list.
The third line contains one integer q (1 ≤ q ≤ 105) — the number of queries.
The fourth line contains q integers d1, d2, ..., dq (1 ≤ dp ≤ 105, p = 1, 2, ..., q) — numbers of months, in which queries are formed.
Months are numbered starting with 1; at the beginning of the first month Prince buys the first m energy-saving lamps.
OutputPrint q lines.
Line #p contains two integers — the number of rooms, in which all old lamps are replaced already, and the number of remaining energy-saving lamps by the end of dpth month.
ExamplesInput5 4Output
3 10 5 2 7
10
5 1 4 8 7 2 3 6 4 7
4 0
1 1
2 3
5 1
5 1
1 5
1 9
4 4
2 3
5 1