from collections import deque

def doRoundRobin(nt,q):
    result = []

    countTime = 0

    while len(nt) > 0:
        tmp = nt.popleft()
        if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0],countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
    return result


if __name__ == '__main__':
    n, q = map(int,input().split())
    
    nameTime = deque()
    for _ in range(n):
        a, b =  input().split()
        nameTime.append([a,(int)(b)])

    resultNameTime = doRoundRobin(nameTime,q)

    for x in resultNameTime:
        print(x[0],x[1]) from collections import deque def doRoundRobin(nt,q):
    result = []

    countTime = 0

    while len(nt) > 0:
        tmp = nt.popleft()
        if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0],countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
    return result doRoundRobin result = [] result [] countTime = 0 countTime 0 while len(nt) > 0:
        tmp = nt.popleft()
        if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0],countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
     len(nt) > 0 len(nt) len nt 0 tmp = nt.popleft() tmp nt.popleft() nt.popleft nt popleft if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0],countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
     tmp[1] <= q tmp[1] tmp 1 q countTime += tmp[1] countTime tmp[1] tmp 1 result.append([tmp[0],countTime]) result.append result append [tmp[0],countTime] tmp[0] tmp 0 countTime tmp[1] -= q tmp[1] tmp 1 q countTime += q countTime q nt.append(tmp) nt.append nt append tmp return result result nt nt q q if __name__ == '__main__':
    n, q = map(int,input().split())
    
    nameTime = deque()
    for _ in range(n):
        a, b =  input().split()
        nameTime.append([a,(int)(b)])

    resultNameTime = doRoundRobin(nameTime,q)

    for x in resultNameTime:
        print(x[0],x[1]) __name__ == '__main__' __name__ '__main__' n, q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q nameTime = deque() nameTime deque() deque for _ in range(n):
        a, b =  input().split()
        nameTime.append([a,(int)(b)])

     _ range(n) range n a, b =  input().split() a input().split() ().split () input split b nameTime.append([a,(int)(b)]) nameTime.append nameTime append [a,(int)(b)] a (int)(b) int b resultNameTime = doRoundRobin(nameTime,q) resultNameTime doRoundRobin(nameTime,q) doRoundRobin nameTime q for x in resultNameTime:
        print(x[0],x[1]) x resultNameTime print(x[0],x[1]) print x[0] x 0 x[1] x 1 def doRoundRobin(nt,q):
    result = []

    countTime = 0

    while len(nt) > 0:
        tmp = nt.popleft()
        if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0],countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
    return result def doRoundRobin(nt,q):
    result = []

    countTime = 0

    while len(nt) > 0:
        tmp = nt.popleft()
        if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0],countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
    return result doRoundRobin q = map(int,input().split()) map(int,input().split()) q b =  input().split() input().split() b nameTime = deque() deque() nameTime resultNameTime = doRoundRobin(nameTime,q) doRoundRobin(nameTime,q) resultNameTime a, b =  input().split() input().split() a n, q = map(int,input().split()) map(int,input().split()) n
from collections import deque

def doRoundRobin(nt,q):
    result = []

    countTime = 0

    while len(nt) > 0:
        tmp = nt.popleft()
        if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0],countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
    return result


if __name__ == '__main__':
    n, q = map(int,input().split())
    
    nameTime = deque()
    for _ in range(n):
        a, b =  input().split()
        nameTime.append([a,(int)(b)])

    resultNameTime = doRoundRobin(nameTime,q)

    for x in resultNameTime:
        print(x[0],x[1])