The Iranian Hazfi Cup is a football tournament organized every year in a knockout format; i.e. the loser of each match is immediately eliminated from the tournament, and the winner gets to play in the next round. Every year, teams participate in this tournament (for some positive integer ). All teams start the tournament in the first round and after each round, half of the teams that are still in the tournament are eliminated. The round is the final round, where two teams compete for the championship. In total, matches are held.
The tournament bracket of the Hazfi Cup is determined ahead of time in the drawing ceremony in the presence of special guests. It determines which teams are facing each other in the first round, and which other teams they might encounter if they advance to the next rounds. Precisely, in the drawing ceremony, all teams are randomly mapped to the positions in the first round as depicted in the figure for .
The Iranian football federation must start organizing the Hazfi Cup . As many of the special guests might refuse to attend the drawing ceremony this year, the federation has decided to use the same tournament bracket as Hazfi Cup . Unfortunately, last year’s tournament bracket is not available, but all match results of last year’s tournament are available in an arbitrary order. It can be shown that the tournament bracket can be uniquely determined from these match results. Your task is to recover the tournament bracket from the match results of Hazfi Cup in order to answer the following fans’ common questions for this year:
The input starts with a line containing two space-separated integers , the number of rounds in the tournament , and , the number of fans' questions . The match results of the Hazfi Cup 2022 come in the next lines; one line for each result. Each match result is of the form:
where teamA and teamB are different non-empty strings of lowercase English letters of length at most 100, and and denote the number of goals scored by teamA and teamB, respectively . In the case of a draw, the winner is determined by penalty shootouts, and the match result is of the form:
where is the number of goals scored by each team during the main game, and and are the number of goals scored by teamA and teamB during the penalty shootouts, respectively . The number of scored goals (i.e., , , , , and ) are all non-negative integers less than 100. Note that each line denoting a match result in the input contains exactly space characters.
The input ends with queries. Each query is given in a separate line containing two different team names delimited by a space character.
For each query in the input, print as the answer, a single integer in a separate line in the output.