Given a tree with nodes, numbered from to . A partial graph of the graph is the graph obtained using a subset of edges such that .
A graph is an -graph if there exists an "x", or if such that .
A graph is an -graph if there exists an "n", or if there exists a simple path of at least nodes.
A graph is an -graph if there exists an "s", or if there exists a simple path of at least nodes.
A graph is an -graph if it satisfies all the conditions above.
Task
You are given queries of the form , asking whether the partial graph of the tree formed by the edges in the interval is an -graph.
Input data
The first line will contain two integers, and , as described above.
Each of the next lines will contain a pair of positive integers and , separated by spaces, representing edge .
Each of the next lines will contain a pair of positive integers and , separated by spaces, representing the -th query.
Output data
Line should contain the answer corresponding to the -th query from the input.
Constraints and clarifications
- ;
- ;
- ;
- denotes the degree of the node in the graph;
- A simple path is a path in which no nodes or edges can appear more than once.
- The , , and can overlap, i.e., they do not have to be disjoint;
- Due to the very large input set, it is recommended to use fastio.
- For tests worth points: ;
- For other tests worth points: ;
- For other tests worth points: for all queries;
- For other tests worth points: ;
- For other tests worth points: no additional constraints.
Example 1
stdin
8 7
1 2
1 3
2 5
2 6
2 4
3 7
7 8
1 1
1 2
1 3
1 4
1 5
1 6
1 7
stdout
0
0
0
0
0
0
1
Explanation
Below you can find the graphical representation of the given tree, where the labels of the edges represent their index (input order).