XOR Tree

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

There is an undirected graph GG with nn vertices. It has an interesting property: if we treat multiple edges as one, the graph GG will become a tree. Alice and Bob invented the following game:

  • At the beginning, Alice and Bob choose two vertices SS and TT, STS \ne T.
  • There is another graph HH with nn vertices and, initially, no edges.
  • On every turn, the current player chooses any edge uvu-v in graph GG, deletes it and changes the state of edge uvu-v in graph HH: if there was no such edge in graph HH, 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 SS and TT in graph HH.
  • If there is no edge in graph GG 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 qq 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 nn and qq: the number of vertices in graph GG and the number of games played by Alice and Bob (2n1052 \le n \le 10^5, 1q1051 \le q \le 10^5).

The next n1n-1 lines contain the description of graph GG. Each line consists of three integers aa, bb and cc (1a,bn1 \le a, b \le n, 1c1091 \le c \le 10^9) which means there are exactly cc edges between vertices aa and bb. It is guaranteed that, if we change all cc to 11, the graph GG will become a tree with nn vertices.

The next qq lines describe the games. Each of these lines contains two integers SS and TT: the parameters of the game (1S,Tn1 \le S, T \le n, STS \ne T).

출력

For each game, print 1 if Alice wins, and print 2 otherwise. Separate the answers with line breaks.