Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
	i %= n
	a = que[i]
	if 0 < a[1] <= q:
		t += a[1]
		que[i][1] = 0
		print a[0],t				
	elif q < a[1]:
		t += q
		que[i][1] = a[1] - q
	i += 1

Fixed submission:
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
    if i >= n: i %= n
    if que[i][1] <= q:
        t += que[i][1]
        print que[i][0],t
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1

Buggy python submission (verdict: Runtime Error):
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
	i %= n
	c = que[i][1]
	if c <= q:
		t += c
		que.pop(i)
		n -= 1
		print a[0],t				
	else:
		t += q
		que[i][1] = c - q
		i += 1

Fixed submission:
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
    if i >= n: i %= n
    if que[i][1] <= q:
        t += que[i][1]
        print que[i][0],t
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1

Buggy python submission (verdict: Runtime Error):
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
	if que[i][1] <= q:
		t += que[i][1]
		que.pop(i)
		n -= 1
		print que[i][0],t				
	else:
		t += q
		que[i][1] = que[i][1] - q
		i = (i+1)%n

Fixed submission:
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
    if i >= n: i %= n
    if que[i][1] <= q:
        t += que[i][1]
        print que[i][0],t
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1

Buggy python submission (verdict: Runtime Error):
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
    if i = n: i = 0
    if que[i][1] <= q:
        t += que[i][1]
        print que[i][0],t
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1

Fixed submission:
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
    if i >= n: i %= n
    if que[i][1] <= q:
        t += que[i][1]
        print que[i][0],t
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1