n,q = map(int,input().split())
A = []
B = []
C = []
t = 0

for i in range(n):
    x,y = input().split()
    A.append([x,int(y)])

while len(A)>0:
    f = A[0][1]
    if f<=q:
        t += f
        B.append(A[0][0])
        C.append(t)
    else:
        t += q
        A[0][1] -= q
        A.append(A[0])
    A.pop(0)

for j in range(len(B)):
    print(B[j],C[j]) n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q A = [] A [] B = [] B [] C = [] C [] t = 0 t 0 for i in range(n):
    x,y = input().split()
    A.append([x,int(y)]) i range(n) range n x,y = input().split() x input().split() ().split () input split y A.append([x,int(y)]) A.append A append [x,int(y)] x int(y) int y while len(A)>0:
    f = A[0][1]
    if f<=q:
        t += f
        B.append(A[0][0])
        C.append(t)
    else:
        t += q
        A[0][1] -= q
        A.append(A[0])
    A.pop(0) len(A)>0 len(A) len A 0 f = A[0][1] f A[0][1] [0] A 0 1 if f<=q:
        t += f
        B.append(A[0][0])
        C.append(t)
    else:
        t += q
        A[0][1] -= q
        A.append(A[0])
     f<=q f q t += f t f B.append(A[0][0]) B.append B append A[0][0] [0] A 0 0 C.append(t) C.append C append t t += q t q A[0][1] -= q A[0][1] [0] A 0 1 q A.append(A[0]) A.append A append A[0] A 0 A.pop(0) A.pop A pop 0 for j in range(len(B)):
    print(B[j],C[j]) j range(len(B)) range len(B) len B print(B[j],C[j]) print B[j] B j C[j] C j q = map(int,input().split()) map(int,input().split()) q B = [] [] B t = 0 0 t t += q q t x,y = input().split() input().split() x n,q = map(int,input().split()) map(int,input().split()) n f = A[0][1] A[0][1] f A = [] [] A y = input().split() input().split() y t += f f t C = [] [] C
n,q = map(int,input().split())
A = []
B = []
C = []
t = 0

for i in range(n):
    x,y = input().split()
    A.append([x,int(y)])

while len(A)>0:
    f = A[0][1]
    if f<=q:
        t += f
        B.append(A[0][0])
        C.append(t)
    else:
        t += q
        A[0][1] -= q
        A.append(A[0])
    A.pop(0)

for j in range(len(B)):
    print(B[j],C[j])
