While on a journey in search of her mother's home, Mayoi Hachikuji continuously finds herself lost within the massive network of roads of her city.
In this city, there are intersections labelled to , joined by directed roads. Being the curious child she is, Mayoi would like to ask you queries about this large and mysterious city.
With her past experience in life leading her to avoid as many trucks as possible, Mayoi asks you the following question:
If I start at intersection and take at most steps, what is the minimal number of passing trucks per minute (denoted by ), over all the intersections I could possibly traverse (denoted by )?
Being a ghost who cannot pass through walls, Mayoi asks you a second question to help her save time:
For the same starting intersection , at how many possible different intersections could I finish my journey by taking exactly steps (denoted by )?
Note: If Mayoi finds herself at an intersection with no outgoing roads and has yet to take exactly steps, she will leave (as such, the intersection will not count as a destination intersection.
Input Specification
The first line of input contains two space-separated integers and , representing the number of intersections and the number of roads which join these intersections respectively.
The second line contains space separated integers , representing the number of trucks which pass through the intersection every minute.
The next lines will each contain two space separated integers and , denoting a directed road from the intersection numbered to the one numbered .
The next line of input contains the integer , representing the number of queries from Mayoi.
The next lines will each contain two space separated integers and .
Constraints
For all subtasks:
Subtask | Points | |||
---|---|---|---|---|
Output Specification
For each of Mayoi's queries, output the desired answers ( and ) to her questions as two space-separated integers on a single line: c d
.
Sample Input 1
3 2
3 1 2
1 2
3 1
4
1 0
3 0
3 1
3 3
Sample Output 1
3 1
2 1
2 1
1 0
Explanation 1
The graph of Sample Input is shown above, with the rate of passing trucks displayed in red.
For Mayoi's first two queries, she does not take any steps. Therefore, the minimum rate of passing trucks is that of the starting intersection. The starting point is also the only possible destination point.
For her last query, the intersection with the lowest rate of trucks steps away from the start is intersection #, with a rate of . There are no intersections exactly steps away from intersection #, so the number of possible destination intersections is .
Sample Input 2
4 4
5 7 3 8
4 1
2 3
2 4
3 1
2
2 1
4 4
Sample Output 2
3 2
5 0
Comments