Medium Accuracy: 14.6% Submissions: 2920 Points: 4
They declared Sonam as bewafa. Although she is not, believe me! She asked a number of queries to people regrading their position in a test. Now its your duty to remove her bewafa tag by answering simple queries. All the students who give test can score from 1 to 10^18. Lower the marks, better the rank. Now instead of directly telling the marks of student they have been assigned groups where marks are distributed in continuous intervals, you have been given l(i) lowest mark of interval i and r(i) highest marks in interval i. So marks distribution in that interval is given as l(i), l(i)+1, l(i)+2 . . . r(i).
Now Sonam ask queries in which she gives rank of the student (x) and you have to tell marks obtained by that student.
Note: rank1 is better than rank2 and rank2 is better than rank3 and so on and the first interval starts from 1.
The first line of input contains an integer T, denoting the no of test cases. Then T test cases follow. Each test case contains two space separated values N and Q denoting the no of groups and number of queries asked respectively. The next line contains N group of two integers separated by space which shows lowest marks in group i ie l(i) and highest marks in group i ie r(i) such that if i < j then r(i) < l(j). The next lines contain Q space separated integers x, denoting rank of student.
For each query output marks obtain by student whose rank is x(1<=x<=10^18).
Explanation: Intervals are from 1 to 10, second interval from 12 to 20 and third 22 to 30.
In this test case, from 1 to 10 , they are given the ranks from 1 to 10 but in the second interval, it is starting from 12 , so we will have to give its rank 11 and so on like this.