The cat Somnorilă is a very sleepy cat! While sleeping, he had a dream in which he and a mouse were in a labyrinth. What is special about this labyrinth is that all the paths between the rooms of the labyrinth can only be traversed in one direction, and during a walk through the labyrinth, he cannot pass through the same room twice. Moreover, only the cat knows the map of the labyrinth, as the mouse does not have the courage to move from his current room. Being a delicate cat, Somnorilă wants to know if, from the room he is currently in, he can reach the mouse's room, so he will know if his dream was a nightmare or a pleasant dream when he wakes up!
Formally, you are given a directed acyclic graph (DAG) with nodes and edges, and questions of the form: can node be accessed from node ?
Task
You need to answer all questions from Somnorilă.
Input data
The first line contains the numbers and , where represents the number of nodes in the graph, and the number of edges. The next lines contain two numbers and , indicating that there is an edge from node to node in the graph. Line contains the number , representing the number of questions. The next lines each contain numbers and , representing a question.
Output data
The output will contain lines, each having a number. Each line contains the answer to question . Print if node can reach node , or otherwise.
Constraints and clarifications
- It is guaranteed that in an edge and in a query, node will be at a lower level than node .
- It is guaranteed that for each node on a level , there will be at least one edge with a node on level , .
- For points, , the tests are NOT grouped.
- For the remaining points, the original constraints apply, and the tests are grouped into 4-5 tests per group.
Example
stdin
12 13
1 4
2 5
3 5
4 6
4 7
4 11
5 6
5 8
5 12
6 9
7 9
7 10
11 12
4
1 9
4 8
7 12
3 6
stdout
1
0
0
1
Explanation
- Node can be accessed from node . (Example path: )
- Node cannot be accessed from node .
- Node cannot be accessed from node .
- Node can be accessed from node . (Example path: )