from collections import deque

n, q = map(int, input().split())
p = deque()
for i in range(n):
    name, t = input().split()
    time = int(t)
    p.append((name, time))
elapsed = 0
while len(p) > 0:
    name, time = p.popleft()
    elapsed += min(q, time)
    if time > q:
        p.append((name, time - q))
    else:
        print(name, elapsed)
 from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q p = deque() p deque() deque for i in range(n):
    name, t = input().split()
    time = int(t)
    p.append((name, time)) i range(n) range n name, t = input().split() name input().split() ().split () input split t time = int(t) time int(t) int t p.append((name, time)) p.append p append (name, time) name time elapsed = 0 elapsed 0 while len(p) > 0:
    name, time = p.popleft()
    elapsed += min(q, time)
    if time > q:
        p.append((name, time - q))
    else:
        print(name, elapsed) len(p) > 0 len(p) len p 0 name, time = p.popleft() name p.popleft() p.popleft p popleft time elapsed += min(q, time) elapsed min(q, time) min q time if time > q:
        p.append((name, time - q))
    else:
        print(name, elapsed) time > q time q p.append((name, time - q)) p.append p append (name, time - q) name time - q time q print(name, elapsed) print name elapsed q = map(int, input().split()) map(int, input().split()) q time = int(t) int(t) time elapsed = 0 0 elapsed t = input().split() input().split() t time = p.popleft() p.popleft() time p = deque() deque() p n, q = map(int, input().split()) map(int, input().split()) n elapsed += min(q, time) min(q, time) elapsed name, time = p.popleft() p.popleft() name name, t = input().split() input().split() name
from collections import deque

n, q = map(int, input().split())
p = deque()
for i in range(n):
    name, t = input().split()
    time = int(t)
    p.append((name, time))
elapsed = 0
while len(p) > 0:
    name, time = p.popleft()
    elapsed += min(q, time)
    if time > q:
        p.append((name, time - q))
    else:
        print(name, elapsed)

