from collections import deque

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

for i in range(n):
    a = input().split()
    Q.append([a[0],int(a[1])])
s = 0

while Q:
    qt = Q.popleft()
    
    if qt[1] > q:
        Q.append([qt[0],qt[1]-q])
        s += q
    else:
        s += qt[1] 
        print(qt[0],s) from collections import deque n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q Q = deque() Q deque() deque for i in range(n):
    a = input().split()
    Q.append([a[0],int(a[1])]) i range(n) range n a = input().split() a input().split() ().split () input split Q.append([a[0],int(a[1])]) Q.append Q append [a[0],int(a[1])] a[0] a 0 int(a[1]) int a[1] a 1 s = 0 s 0 while Q:
    qt = Q.popleft()
    
    if qt[1] > q:
        Q.append([qt[0],qt[1]-q])
        s += q
    else:
        s += qt[1] 
        print(qt[0],s) Q qt = Q.popleft() qt Q.popleft() Q.popleft Q popleft if qt[1] > q:
        Q.append([qt[0],qt[1]-q])
        s += q
    else:
        s += qt[1] 
        print(qt[0],s) qt[1] > q qt[1] qt 1 q Q.append([qt[0],qt[1]-q]) Q.append Q append [qt[0],qt[1]-q] qt[0] qt 0 qt[1]-q qt[1] qt 1 q s += q s q s += qt[1] s qt[1] qt 1 print(qt[0],s) print qt[0] qt 0 s q = map(int,input().split()) map(int,input().split()) q n,q = map(int,input().split()) map(int,input().split()) n s = 0 0 s a = input().split() input().split() a Q = deque() deque() Q s += qt[1] qt[1] s s += q q s qt = Q.popleft() Q.popleft() qt
from collections import deque

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

for i in range(n):
    a = input().split()
    Q.append([a[0],int(a[1])])
s = 0

while Q:
    qt = Q.popleft()
    
    if qt[1] > q:
        Q.append([qt[0],qt[1]-q])
        s += q
    else:
        s += qt[1] 
        print(qt[0],s)