from collections import deque


n, q = map(int, input().split())
n_t = deque()
for i in range(n):
    s, j = input().split()
    n_t.append([str(s), int(j)])

timer = 0

while n_t:
    s, i = n_t.popleft()
    if i > q:
        i -= q
        timer += q
        n_t.append([s, i])
    else:
        timer += i
        print("{0} {1}".format(s, timer)) from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q n_t = deque() n_t deque() deque for i in range(n):
    s, j = input().split()
    n_t.append([str(s), int(j)]) i range(n) range n s, j = input().split() s input().split() ().split () input split j n_t.append([str(s), int(j)]) n_t.append n_t append [str(s), int(j)] str(s) str s int(j) int j timer = 0 timer 0 while n_t:
    s, i = n_t.popleft()
    if i > q:
        i -= q
        timer += q
        n_t.append([s, i])
    else:
        timer += i
        print("{0} {1}".format(s, timer)) n_t s, i = n_t.popleft() s n_t.popleft() n_t.popleft n_t popleft i if i > q:
        i -= q
        timer += q
        n_t.append([s, i])
    else:
        timer += i
        print("{0} {1}".format(s, timer)) i > q i q i -= q i q timer += q timer q n_t.append([s, i]) n_t.append n_t append [s, i] s i timer += i timer i print("{0} {1}".format(s, timer)) print "{0} {1}".format(s, timer) "{0} {1}".format "{0} {1}" format s timer q = map(int, input().split()) map(int, input().split()) q j = input().split() input().split() j s, i = n_t.popleft() n_t.popleft() s timer += q q timer i = n_t.popleft() n_t.popleft() i i -= q q i timer += i i timer timer = 0 0 timer n, q = map(int, input().split()) map(int, input().split()) n n_t = deque() deque() n_t s, j = input().split() input().split() s
from collections import deque


n, q = map(int, input().split())
n_t = deque()
for i in range(n):
    s, j = input().split()
    n_t.append([str(s), int(j)])

timer = 0

while n_t:
    s, i = n_t.popleft()
    if i > q:
        i -= q
        timer += q
        n_t.append([s, i])
    else:
        timer += i
        print("{0} {1}".format(s, timer))