Student Sections

See the original problem on HackerRank.

The school term starts soon, and the students need to be sorted into their respective sections. There are n n students numbered 1 1 to n n , and m m sections numbered 1 1 to m m .

Section needs to have exactly ai a_i students. To simplify the process, the school has decided to assign students to sections in increasing student number, which means the first a1 a_1 students will be assigned section 1 1 , the next a2 a_2 students will be assigned section 2 2 , and so on.

Your student number is k k . Which section will you be assigned to?

Input Format

The first line of input contains t t , the number of scenarios.

The description of t t scenarios follow, each described in two lines. The first line contains three space-separated integers n n , k k and m m . The second line contains space-separated integers a1,a2,,am a_1, a_2, …, a_m .

Constraints

  • 1t250 1 \leq t \leq 250
  • 1kn500 1 \leq k \leq n \leq 500
  • 1m500 1 \leq m \leq 500
  • 1ain 1 \leq a_i \leq n
  • ai+a2++am=n a_i + a_2 + … + a_m = n

Output

For each scenario, print a single line containing a single integer denoting the section in which student number kk will be assigned to.

Solutions

Wait! Have you challenged yourself with this problem? If yes, click here to show the solution.
We've worked on this challenge in these gyms: modena  padua  milan  turin  bassano-del-grappa