# Haircut
# https://code.google.com/codejam/contest/4224486/dashboard#s=p1


def solve(start, m):
    n = start
    c = [0] * len(m)

    while n > 0:
        # assign a customer for every idle barber
        while 0 in c:
            d = c.index(0)
            if n == 1:
                return d + 1
            c[d] = m[d]
            n -= 1

        # period has repeated, n can be reduced
        if all(x == 1 for x in c):
            period = start - n
            n = n % period or period

        # reduce time by 1 minute for all barbers
        for i in range(len(c)):
            c[i] -= 1

for tc in range(int(input())):
    b, n = (int(x) for x in input().split())
    m = [int(x) for x in input().split()]
    print('Case #{}: {}'.format(tc + 1, solve(n, m)))

8f0801e11e6c8dd0f2704b37c07a654911ac5d8b
<mask token>

def solve(start, m):
    n = start
    c = [0] * len(m)
    while n > 0:
        while 0 in c:
            d = c.index(0)
            if n == 1:
                return d + 1
            c[d] = m[d]
            n -= 1
        if all(x == 1 for x in c):
            period = start - n
            n = n % period or period
        for i in range(len(c)):
            c[i] -= 1


<mask token>

def solve(start, m):
    n = start
    c = [0] * len(m)
    while n > 0:
        while 0 in c:
            d = c.index(0)
            if n == 1:
                return d + 1
            c[d] = m[d]
            n -= 1
        if all(x == 1 for x in c):
            period = start - n
            n = n % period or period
        for i in range(len(c)):
            c[i] -= 1


for tc in range(int(input())):
    b, n = (int(x) for x in input().split())
    m = [int(x) for x in input().split()]
    print('Case #{}: {}'.format(tc + 1, solve(n, m)))

# Haircut
# https://code.google.com/codejam/contest/4224486/dashboard#s=p1


def solve(start, m):
    n = start
    c = [0] * len(m)

    while n > 0:
        # assign a customer for every idle barber
        while 0 in c:
            d = c.index(0)
            if n == 1:
                return d + 1
            c[d] = m[d]
            n -= 1

        # period has repeated, n can be reduced
        if all(x == 1 for x in c):
            period = start - n
            n = n % period or period

        # reduce time by 1 minute for all barbers
        for i in range(len(c)):
            c[i] -= 1

for tc in range(int(input())):
    b, n = (int(x) for x in input().split())
    m = [int(x) for x in input().split()]
    print('Case #{}: {}'.format(tc + 1, solve(n, m)))
