n,q=map(int,input().split())
Q=[]
sum=0
for i in range(n):
    tmp=input().split()
    tmp[1]=int(tmp[1])
    Q.append(tmp[0])
    Q.append(tmp[1])

loop=0
while loop==0:
    for i in range(len(Q)//2):
        tmp=[Q[0],Q[1]]
        if tmp[1]>q:
            sum+=q
            Q.append(tmp[0])
            Q.append(tmp[1]-q)
        else:
            sum+=tmp[1]
            print(tmp[0],sum)
        Q.pop(0)
        Q.pop(0)
    if len(Q)==0:
        break
 n,q=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q Q=[] Q [] sum=0 sum 0 for i in range(n):
    tmp=input().split()
    tmp[1]=int(tmp[1])
    Q.append(tmp[0])
    Q.append(tmp[1]) i range(n) range n tmp=input().split() tmp input().split() ().split () input split tmp[1]=int(tmp[1]) tmp[1] tmp 1 int(tmp[1]) int tmp[1] tmp 1 Q.append(tmp[0]) Q.append Q append tmp[0] tmp 0 Q.append(tmp[1]) Q.append Q append tmp[1] tmp 1 loop=0 loop 0 while loop==0:
    for i in range(len(Q)//2):
        tmp=[Q[0],Q[1]]
        if tmp[1]>q:
            sum+=q
            Q.append(tmp[0])
            Q.append(tmp[1]-q)
        else:
            sum+=tmp[1]
            print(tmp[0],sum)
        Q.pop(0)
        Q.pop(0)
    if len(Q)==0:
        break loop==0 loop 0 for i in range(len(Q)//2):
        tmp=[Q[0],Q[1]]
        if tmp[1]>q:
            sum+=q
            Q.append(tmp[0])
            Q.append(tmp[1]-q)
        else:
            sum+=tmp[1]
            print(tmp[0],sum)
        Q.pop(0)
        Q.pop(0)
     i range(len(Q)//2) range len(Q)//2 len(Q) len Q 2 tmp=[Q[0],Q[1]] tmp [Q[0],Q[1]] Q[0] Q 0 Q[1] Q 1 if tmp[1]>q:
            sum+=q
            Q.append(tmp[0])
            Q.append(tmp[1]-q)
        else:
            sum+=tmp[1]
            print(tmp[0],sum)
         tmp[1]>q tmp[1] tmp 1 q sum+=q sum q Q.append(tmp[0]) Q.append Q append tmp[0] tmp 0 Q.append(tmp[1]-q) Q.append Q append tmp[1]-q tmp[1] tmp 1 q sum+=tmp[1] sum tmp[1] tmp 1 print(tmp[0],sum) print tmp[0] tmp 0 sum Q.pop(0) Q.pop Q pop 0 Q.pop(0) Q.pop Q pop 0 if len(Q)==0:
        break len(Q)==0 len(Q) len Q 0 break q=map(int,input().split()) map(int,input().split()) q tmp=input().split() input().split() tmp sum=0 0 sum tmp=[Q[0],Q[1]] [Q[0],Q[1]] tmp Q=[] [] Q loop=0 0 loop sum+=q q sum sum+=tmp[1] tmp[1] sum n,q=map(int,input().split()) map(int,input().split()) n
n,q=map(int,input().split())
Q=[]
sum=0
for i in range(n):
    tmp=input().split()
    tmp[1]=int(tmp[1])
    Q.append(tmp[0])
    Q.append(tmp[1])

loop=0
while loop==0:
    for i in range(len(Q)//2):
        tmp=[Q[0],Q[1]]
        if tmp[1]>q:
            sum+=q
            Q.append(tmp[0])
            Q.append(tmp[1]-q)
        else:
            sum+=tmp[1]
            print(tmp[0],sum)
        Q.pop(0)
        Q.pop(0)
    if len(Q)==0:
        break

