Under construction

Still being built. Things may change

Barber Shop Queue

Interview

Time limit5sMemory limit512 MB

Summary
Find which of B barbers with different cutting times serves the Nth customer when ties go to the smallest barber number.
Level

Medium5 of 10

Topics
Binary search, Math
Solved
No attempts yet

Problem

You are waiting in a long line for a haircut at a popular barber shop. The shop has BB barbers on duty, numbered 1 through BB. Barber kk always takes exactly MkM_k minutes to cut one customer's hair, and a barber cuts only one customer's hair at a time. As soon as a barber finishes, he takes the next customer.

The customer at the head of the line goes to the free barber with the smallest number. If no barber is free, that customer waits until one becomes free.

You are the NNth person in line, and the shop has just opened. Find the number of the barber who will cut your hair.

Input

The first line contains the number of test cases TT. TT test cases follow, and each one consists of two lines.

The first line contains the number of barbers BB and your place in line NN, separated by a space. The customer at the head of the line is number 1, the next one is number 2, and so on. The second line contains M1,M2,…,MBM_1, M_2, \dots, M_B, separated by spaces.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤B≤10001 \le B \le 1000
  • 1≤N≤1091 \le N \le 10^9
  • 1≤Mk≤1000001 \le M_k \le 100000

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the number of the barber who will cut your hair.

Explanation

Consider the first example case. You are the fourth customer, barber 1 takes 10 minutes and barber 2 takes 5 minutes. The moment the shop opens, the first customer can choose between barbers 1 and 2, so she goes to barber 1, the smaller number. The second customer goes straight to barber 2. The third customer waits because no barber is free. After 5 minutes barber 2 finishes the second customer and takes the third one. After 10 minutes barbers 1 and 2 both become free, and you are next, so you choose barber 1 out of the two.

Examples2

  1. Example 1

    Input
    3
    2 4
    10 5
    3 12
    7 7 7
    3 8
    4 2 1
    
    Expected output
    Case #1: 1
    Case #2: 3
    Case #3: 1
    
  2. Example 2

    Input
    3
    1 1
    1
    1 1000000000
    100000
    5 3
    9 9 9 9 9
    
    Expected output
    Case #1: 1
    Case #2: 1
    Case #3: 3