#ALDS1_3-B Elementary data structures - Queue
n,q = [int(x) for x in input().split()]
Q=[]
for i in range(n):
    Q.append(input().split())
t=0
res=[]
while Q!=[]:
    if int(Q[0][1])<=q:
        res.append([Q[0][0],int(Q[0][1])+t])
        t+=int(Q[0][1])
    else:
        Q.append([Q[0][0],int(Q[0][1])-q])
        t+=q
    del Q[0]
for i in res:
    print(i[0]+" "+str(i[1])) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n,q = [int(x) for x in input().split()] n [int(x) for x in input().split()] q Q=[] Q [] for i in range(n):
    Q.append(input().split()) i range(n) range n Q.append(input().split()) Q.append Q append input().split() ().split () input split t=0 t 0 res=[] res [] while Q!=[]:
    if int(Q[0][1])<=q:
        res.append([Q[0][0],int(Q[0][1])+t])
        t+=int(Q[0][1])
    else:
        Q.append([Q[0][0],int(Q[0][1])-q])
        t+=q
    del Q[0] Q!=[] Q [] if int(Q[0][1])<=q:
        res.append([Q[0][0],int(Q[0][1])+t])
        t+=int(Q[0][1])
    else:
        Q.append([Q[0][0],int(Q[0][1])-q])
        t+=q
     int(Q[0][1])<=q int(Q[0][1]) int Q[0][1] [0] Q 0 1 q res.append([Q[0][0],int(Q[0][1])+t]) res.append res append [Q[0][0],int(Q[0][1])+t] Q[0][0] [0] Q 0 0 int(Q[0][1])+t int(Q[0][1]) int Q[0][1] [0] Q 0 1 t t+=int(Q[0][1]) t int(Q[0][1]) int Q[0][1] [0] Q 0 1 Q.append([Q[0][0],int(Q[0][1])-q]) Q.append Q append [Q[0][0],int(Q[0][1])-q] Q[0][0] [0] Q 0 0 int(Q[0][1])-q int(Q[0][1]) int Q[0][1] [0] Q 0 1 q t+=q t q del Q[0] Q[0] Q 0 for i in res:
    print(i[0]+" "+str(i[1])) i res print(i[0]+" "+str(i[1])) print i[0]+" "+str(i[1]) i[0]+" " i[0] i 0 " " str(i[1]) str i[1] i 1 t+=q q t t+=int(Q[0][1]) int(Q[0][1]) t q = [int(x) for x in input().split()] [int(x) for x in input().split()] q t=0 0 t Q=[] [] Q n,q = [int(x) for x in input().split()] [int(x) for x in input().split()] n res=[] [] res
#ALDS1_3-B Elementary data structures - Queue
n,q = [int(x) for x in input().split()]
Q=[]
for i in range(n):
    Q.append(input().split())
t=0
res=[]
while Q!=[]:
    if int(Q[0][1])<=q:
        res.append([Q[0][0],int(Q[0][1])+t])
        t+=int(Q[0][1])
    else:
        Q.append([Q[0][0],int(Q[0][1])-q])
        t+=q
    del Q[0]
for i in res:
    print(i[0]+" "+str(i[1]))