from collections import deque

n, q = map(int, raw_input().split())
task = [raw_input().split() for _ in range(n)]

for t in task:
    t[1] = int(t[1])

Q = deque(task)
elaps = 0

while len(Q) > 0:
    u = Q.popleft()
    c = min(u[1], q)
    u[1] -= c
    elaps += c

    if u[1] > 0:
        Q.append(u)
    else:
        print u[0], elaps from collections import deque n, q = map(int, raw_input().split()) n map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split q raw_input().split() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) raw_input().split() ().split () raw_input split task = [raw_input().split() for _ in range(n)] task [raw_input().split() for _ in range(n)] for t in task:
    t[1] = int(t[1]) t task t[1] = int(t[1]) t[1] t 1 int(t[1]) int t[1] t 1 Q = deque(task) Q deque(task) deque task elaps = 0 elaps 0 while len(Q) > 0:
    u = Q.popleft()
    c = min(u[1], q)
    u[1] -= c
    elaps += c

    if u[1] > 0:
        Q.append(u)
    else:
        print u[0], elaps len(Q) > 0 len(Q) len Q 0 u = Q.popleft() u Q.popleft() Q.popleft Q popleft c = min(u[1], q) c min(u[1], q) min u[1] u 1 q u[1] -= c u[1] u 1 c elaps += c elaps c if u[1] > 0:
        Q.append(u)
    else:
        print u[0], elaps u[1] > 0 u[1] u 1 0 Q.append(u) Q.append Q append u print u[0] u 0 elaps q = map(int, raw_input().split()) map(int, raw_input().split()) q c = min(u[1], q) min(u[1], q) c n, q = map(int, raw_input().split()) map(int, raw_input().split()) n Q = deque(task) deque(task) Q u = Q.popleft() Q.popleft() u elaps = 0 0 elaps task = [raw_input().split() for _ in range(n)] [raw_input().split() for _ in range(n)] task elaps += c c elaps
from collections import deque

n, q = map(int, raw_input().split())
task = [raw_input().split() for _ in range(n)]

for t in task:
    t[1] = int(t[1])

Q = deque(task)
elaps = 0

while len(Q) > 0:
    u = Q.popleft()
    c = min(u[1], q)
    u[1] -= c
    elaps += c

    if u[1] > 0:
        Q.append(u)
    else:
        print u[0], elaps