XOR Tree
시간 제한2초메모리 제한256 MB
간선에 중복 개수가 있는 트리에서 각 질의 쌍 S, T에 대해 간선 토글 게임의 승자를 판정합니다.
문제
There is an undirected graph with vertices. It has an interesting property: if we treat multiple edges as one, the graph will become a tree. Alice and Bob invented the following game:
- At the beginning, Alice and Bob choose two vertices and , .
- There is another graph with vertices and, initially, no edges.
- On every turn, the current player chooses any edge in graph , deletes it and changes the state of edge in graph : if there was no such edge in graph , it appears, and if there was such an edge, it disappears.
- Alice wins if there exists a moment of time when there is a path between and in graph .
- If there is no edge in graph and Alice hasn't won yet, Bob wins.
- Players take turns, Alice moves first.
Children like the game very much so they have played it times. Now they are wondering who would win in each game if they were playing optimally. Help them find it out!
입력
The first line of input contains two integers and : the number of vertices in graph and the number of games played by Alice and Bob (, ).
The next lines contain the description of graph . Each line consists of three integers , and (, ) which means there are exactly edges between vertices and . It is guaranteed that, if we change all to , the graph will become a tree with vertices.
The next lines describe the games. Each of these lines contains two integers and : the parameters of the game (, ).
출력
For each game, print 1 if Alice wins, and print 2 otherwise. Separate the answers with line breaks.