n, q = map(int, input().split())

queue = []

for i in range(n):
    name, time = map(str, input().split())
    queue.append([name, int(time)])

time = 0

while len(queue) != 0:
    p = queue.pop(0)
    if p[1] <= q:
        time += p[1]
        print(p[0], time)
    else:
        time += q
        p[1] -= q
        queue.append(p)
 n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q queue = [] queue [] for i in range(n):
    name, time = map(str, input().split())
    queue.append([name, int(time)]) i range(n) range n name, time = map(str, input().split()) name map(str, input().split()) map str input().split() ().split () input split time queue.append([name, int(time)]) queue.append queue append [name, int(time)] name int(time) int time time = 0 time 0 while len(queue) != 0:
    p = queue.pop(0)
    if p[1] <= q:
        time += p[1]
        print(p[0], time)
    else:
        time += q
        p[1] -= q
        queue.append(p) len(queue) != 0 len(queue) len queue 0 p = queue.pop(0) p queue.pop(0) queue.pop queue pop 0 if p[1] <= q:
        time += p[1]
        print(p[0], time)
    else:
        time += q
        p[1] -= q
        queue.append(p) p[1] <= q p[1] p 1 q time += p[1] time p[1] p 1 print(p[0], time) print p[0] p 0 time time += q time q p[1] -= q p[1] p 1 q queue.append(p) queue.append queue append p q = map(int, input().split()) map(int, input().split()) q name, time = map(str, input().split()) map(str, input().split()) name time = map(str, input().split()) map(str, input().split()) time p = queue.pop(0) queue.pop(0) p queue = [] [] queue time += q q time n, q = map(int, input().split()) map(int, input().split()) n time = 0 0 time time += p[1] p[1] time
n, q = map(int, input().split())

queue = []

for i in range(n):
    name, time = map(str, input().split())
    queue.append([name, int(time)])

time = 0

while len(queue) != 0:
    p = queue.pop(0)
    if p[1] <= q:
        time += p[1]
        print(p[0], time)
    else:
        time += q
        p[1] -= q
        queue.append(p)

