In a kingdom with \(N\) cities connected by \(N-1\) roads, the king's palace is located in the first city. Each city has a specific number of guards, given in an array \(Guards[]\), where \(Guards[i]\) is the number of guards in the city \(i\). The kingdom must assess the risk of revolts starting from any city and how close rebels could get to the king's palace. The guards' effectiveness is such that one guard can stop one rebel.
To tackle this, the king has asked you to develop a method for analyzing such scenarios. This includes answering queries of type 'query(\(U\), \(X\))', where \(U\) represents the city where the revolt might begin, and \(X\) indicates the number of protestors at the start. Your task is to determine for each query the nearest city to the king's palace (i.e., city 1) that the rebels can reach.
Note: If the rebels can reach City 1, you should print City 1, as this is the city where the King's palace is located.
Input format
Output format
For each test case, answer all the \(Q\) queries. For each query, print in a new line the nearest city to the king's palace (i.e., city 1) that the rebels can reach.
Constraints
\(1 \leq T \leq 10^5 \\ 3 \leq N \leq10^6 \\ 1≤u,v≤N\\ 1≤Guards[i]≤10^9\ ∀\ i∈[1,N] \\ 1 \leq Q \leq 10^6\\ 1≤U≤N\\ 1≤X≤10^{15} \\ \text{The sum of all values of N over all test cases doesn't exceed }10^6 \\ \text{The sum of all values of Q over all test cases doesn't exceed }10^6\)
The first line denotes T = 1.
For test case \(1\):
We are given:
Now,