Consider a state with cities (numbered from to ) and roads (bidirectional). A road connects two cities. Using these roads, we can reach any city from any city.
Each city has a single player, who has a set of cards. Each card has a non-negative number written on it. Also, the player living in the city has a non-negative number assigned. The set bits in this number, (numbered as 0, 1, 2.. from right to left) define the set of cards the player has i.e. if the bit is set, the player has the card with number .(for number 7, the player will have 0th,1st and the 2nd card, because the binary representation of 7 is 111)
Now, Yashwanth (our protagonist), is planning a battle journey. Consider the following details about the expedition:
1) Initially Yashwant, doesn't have any cards.
2) He will start at city and travel along the simple path to reach city .
3)The Winner of a battle will have the card, if and only if, EXACTLY ONE of the players battling, has the card.
In order to plan correctly, and earn as many cards as possible, Yashwant wants to know the cards he will have at the end of each journey.
ASSUMING that Yashwanth wins at each city, answer the queries below.
NOTE: The answer to each query is a number, bit of which will be set if Yashwant will have the card at the end of the journey.
NOTE: Queries are independent and don't affect the cards of the losing player.
Input:
The first line of input will have and (number of cities and queries respectively) ()
The second line will have numbers, representing the number of city . ()
The next lines will have two cities and , connecting and
Then we will have queries, each query will have two cities and .. the starting point and the ending point
Output:
Print lines, the line should have the answer for the query
For the first query, we will start at city 5 and end at city 6, the simple path is 5-4-6.
Initially, we have no cards, after winning the battle at city 5 we will have 2 cards(0th and the 2nd), after the battle at city 4 we will have only one card (0th card), and finally, after city 6 we will have 3 cards(0th,1st and the 2nd), therefore the number where the 0th,1st and the 2nd bit are set is 7