Shahir's promposal's going great! Kenneth, another friend, pulls up to Shahir's house. Dhruvit assumes his mailman costume, and Shahir (taped inside the package) is put into the trunk of Kenneth's car. Why is Shahir put into the trunk of the car? It would be awkward if he got into the box at his date's house while she watched. It would be much more romantic if his date saw Dhruvit pulling the box from the trunk of the car, like a real delivery!
The two start driving to Shahir's date's house, through Shahir's neighbourhood:
Shahir, devoid of any senses and stuck within a cardboard box (which is in turn stuck within the trunk of the car), knows nothing: he's assuming that Kenneth's at a red light. However, Dhruvit just made the sudden realization that Kenneth doesn't have his G2 Driver's License. Nor his G1. This isn't even his car. And, if the police officer were to open the trunk of the car, he would find a kidnapped minor tied up and stuffed into a cardboard box.
It would be easier to just run. While the officer was halfway between the two cars, Kenneth slammed on the pedal, going 0 to 60, and started racing down the roads. Dhruvit starts screaming. Shahir, still inside the box, practices his promposal. The police officer started chasing them again, sirens blaring, but that didn't matter. What mattered was getting Shahir to his date's house and his promposal. The only problem was, Kenneth didn't know where he was!
While still driving, Dhruvit took out his laptop and made some edits to the program from the last problem. He still has the map of Shahir's neighbourhood —
Input Specification
On the first line will be four space separated integers:
: The number of houses in Shahir's neighbourhood. : The number of roads in Shahir's neighbourhood. : Shahir's date lives in house . : The number of queries that the program must answer.
The next
The next
Output Specification
For each query and on each line, print the shortest distance to Shahir's date's house from the house specified in the query. If you cannot reach Shahir's date's house from the query house, print -1
.
Sample Input
6 7 6 5
1 2 1
2 3 1
2 5 3
5 1 200
3 4 2000
4 5 3
4 6 1000
1
2
3
4
5
Sample Output
1007
1006
1007
1000
1003
Warning
Don't code and drive, kids.
Comments
Never mind. I solved it
Note that it is possible for them to be at the date's house already and that it is guaranteed for only one edge to exist between two nodes