class Data:
    def __init__(self):
        self.name = ""
        self.time = -1
    def printdata(self,sum):
        print(self.name,sum)
    def datain(self,name,time):
        self.name = name
        self.time = int(time)

def enqueue(Q,x):
    global tail
    Q[tail] = x
    if(tail+1 == n+1):
        tail = 0
    else:
        tail += 1

def dequeue():
    global head
    if(head+1 == n+1):
        head = 0
    else:
        head += 1

n,q = map(int,input().split())
A = [Data()]
head = 0
tail = n
sum = 0

for i in range(n):
    d = list(map(str,input().split()))
    A.append(Data())
    A[i].datain(d[0],d[1])
A.append(Data()) #要素数1追加

while(head != tail):
    if(A[head].time - q > 0):
        A[head].time -= q
        enqueue(A,A[head])
        dequeue()
        sum += q
    else:
        sum += A[head].time
        A[head].printdata(sum)
        dequeue() class Data:
    def __init__(self):
        self.name = ""
        self.time = -1
    def printdata(self,sum):
        print(self.name,sum)
    def datain(self,name,time):
        self.name = name
        self.time = int(time) Data def __init__(self):
        self.name = ""
        self.time = -1
     __init__ self.name = "" self.name self name "" self.time = -1 self.time self time -1 self self def printdata(self,sum):
        print(self.name,sum)
     printdata print(self.name,sum) print self.name self name sum self self sum sum def datain(self,name,time):
        self.name = name
        self.time = int(time) datain self.name = name self.name self name name self.time = int(time) self.time self time int(time) int time self self name name time time def enqueue(Q,x):
    global tail
    Q[tail] = x
    if(tail+1 == n+1):
        tail = 0
    else:
        tail += 1 enqueue global tail Q[tail] = x Q[tail] Q tail x if(tail+1 == n+1):
        tail = 0
    else:
        tail += 1 tail+1 == n+1 tail+1 tail 1 n+1 n 1 tail = 0 tail 0 tail += 1 tail 1 Q Q x x def dequeue():
    global head
    if(head+1 == n+1):
        head = 0
    else:
        head += 1 dequeue global head if(head+1 == n+1):
        head = 0
    else:
        head += 1 head+1 == n+1 head+1 head 1 n+1 n 1 head = 0 head 0 head += 1 head 1 n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q A = [Data()] A [Data()] Data() Data head = 0 head 0 tail = n tail n sum = 0 sum 0 for i in range(n):
    d = list(map(str,input().split()))
    A.append(Data())
    A[i].datain(d[0],d[1]) i range(n) range n d = list(map(str,input().split())) d list(map(str,input().split())) list map(str,input().split()) map str input().split() ().split () input split A.append(Data()) A.append A append Data() Data A[i].datain(d[0],d[1]) [i].datain [i] A i datain d[0] d 0 d[1] d 1 A.append(Data()) A.append A append Data() Data while(head != tail):
    if(A[head].time - q > 0):
        A[head].time -= q
        enqueue(A,A[head])
        dequeue()
        sum += q
    else:
        sum += A[head].time
        A[head].printdata(sum)
        dequeue() head != tail head tail if(A[head].time - q > 0):
        A[head].time -= q
        enqueue(A,A[head])
        dequeue()
        sum += q
    else:
        sum += A[head].time
        A[head].printdata(sum)
        dequeue() A[head].time - q > 0 A[head].time - q A[head].time [head] A head time q 0 A[head].time -= q A[head].time [head] A head time q enqueue(A,A[head]) enqueue A A[head] A head dequeue() dequeue sum += q sum q sum += A[head].time sum A[head].time [head] A head time A[head].printdata(sum) [head].printdata [head] A head printdata sum dequeue() dequeue def enqueue(Q,x):
    global tail
    Q[tail] = x
    if(tail+1 == n+1):
        tail = 0
    else:
        tail += 1 def enqueue(Q,x):
    global tail
    Q[tail] = x
    if(tail+1 == n+1):
        tail = 0
    else:
        tail += 1 enqueue tail = n n tail n,q = map(int,input().split()) map(int,input().split()) n sum += q q sum class Data:
    def __init__(self):
        self.name = ""
        self.time = -1
    def printdata(self,sum):
        print(self.name,sum)
    def datain(self,name,time):
        self.name = name
        self.time = int(time) class Data:
    def __init__(self):
        self.name = ""
        self.time = -1
    def printdata(self,sum):
        print(self.name,sum)
    def datain(self,name,time):
        self.name = name
        self.time = int(time) Data A = [Data()] [Data()] A sum += A[head].time A[head].time sum head = 0 0 head sum = 0 0 sum q = map(int,input().split()) map(int,input().split()) q d = list(map(str,input().split())) list(map(str,input().split())) d def dequeue():
    global head
    if(head+1 == n+1):
        head = 0
    else:
        head += 1 def dequeue():
    global head
    if(head+1 == n+1):
        head = 0
    else:
        head += 1 dequeue
class Data:
    def __init__(self):
        self.name = ""
        self.time = -1
    def printdata(self,sum):
        print(self.name,sum)
    def datain(self,name,time):
        self.name = name
        self.time = int(time)

def enqueue(Q,x):
    global tail
    Q[tail] = x
    if(tail+1 == n+1):
        tail = 0
    else:
        tail += 1

def dequeue():
    global head
    if(head+1 == n+1):
        head = 0
    else:
        head += 1

n,q = map(int,input().split())
A = [Data()]
head = 0
tail = n
sum = 0

for i in range(n):
    d = list(map(str,input().split()))
    A.append(Data())
    A[i].datain(d[0],d[1])
A.append(Data()) #要素数1追加

while(head != tail):
    if(A[head].time - q > 0):
        A[head].time -= q
        enqueue(A,A[head])
        dequeue()
        sum += q
    else:
        sum += A[head].time
        A[head].printdata(sum)
        dequeue()
