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

queue = []

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

time = 0
ans = []

while queue:
    tmp = queue.pop(0)
    if tmp[1] > q:
        tmp[1] -= q
        time += q
        queue.append(tmp)
    else:
        time += tmp[1]
        ans.append((tmp[0],time))

for x in ans:
    print(x[0], x[1]) n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q queue = [] queue [] for _ in range(n):
    name, time = input().split()
    time = int(time)
    queue.append([name,time]) _ range(n) range n name, time = input().split() name input().split() ().split () input split time time = int(time) time int(time) int time queue.append([name,time]) queue.append queue append [name,time] name time time = 0 time 0 ans = [] ans [] while queue:
    tmp = queue.pop(0)
    if tmp[1] > q:
        tmp[1] -= q
        time += q
        queue.append(tmp)
    else:
        time += tmp[1]
        ans.append((tmp[0],time)) queue tmp = queue.pop(0) tmp queue.pop(0) queue.pop queue pop 0 if tmp[1] > q:
        tmp[1] -= q
        time += q
        queue.append(tmp)
    else:
        time += tmp[1]
        ans.append((tmp[0],time)) tmp[1] > q tmp[1] tmp 1 q tmp[1] -= q tmp[1] tmp 1 q time += q time q queue.append(tmp) queue.append queue append tmp time += tmp[1] time tmp[1] tmp 1 ans.append((tmp[0],time)) ans.append ans append (tmp[0],time) tmp[0] tmp 0 time for x in ans:
    print(x[0], x[1]) x ans print(x[0], x[1]) print x[0] x 0 x[1] x 1 tmp = queue.pop(0) queue.pop(0) tmp q = map(int,input().split()) map(int,input().split()) q n,q = map(int,input().split()) map(int,input().split()) n ans = [] [] ans time += tmp[1] tmp[1] time time += q q time time = int(time) int(time) time time = 0 0 time time = input().split() input().split() time queue = [] [] queue name, time = input().split() input().split() name
n,q = map(int,input().split())

queue = []

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

time = 0
ans = []

while queue:
    tmp = queue.pop(0)
    if tmp[1] > q:
        tmp[1] -= q
        time += q
        queue.append(tmp)
    else:
        time += tmp[1]
        ans.append((tmp[0],time))

for x in ans:
    print(x[0], x[1])
