n,q = map(int, input().split())
MAX = n + 2
Q = [0 for i in range(MAX)]
head = 0
tail = 0

def enqueue(u, t):
    global tail
    Q[tail] = [u, t]
    tail = (tail + 1) % MAX

def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) %MAX
    return [x,t]
for i in range(n):
    P = list(input().split())
    enqueue(P[0], int(P[1]))

elaps = 0
while head != tail:
    u,t = dequeue()
    c = min(q, t)
    t -= c
    elaps += c
    if t > 0:
        enqueue(u,t)
    else:
        print(u + " " + str(elaps)) n,q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q MAX = n + 2 MAX n + 2 n 2 0 for i in range(MAX) for i in range(MAX) i range(MAX) range MAX for i in range(MAX) 0 Q = [0 for i in range(MAX)] Q [0 for i in range(MAX)] head = 0 head 0 tail = 0 tail 0 def enqueue(u, t):
    global tail
    Q[tail] = [u, t]
    tail = (tail + 1) % MAX enqueue global tail Q[tail] = [u, t] Q[tail] Q tail [u, t] u t tail = (tail + 1) % MAX tail (tail + 1) % MAX tail + 1 tail 1 MAX u u t t def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) %MAX
    return [x,t] dequeue global head x,t = Q[head] x Q[head] Q head t head = (head + 1) %MAX head (head + 1) %MAX head + 1 head 1 MAX return [x,t] [x,t] x t for i in range(n):
    P = list(input().split())
    enqueue(P[0], int(P[1])) i range(n) range n P = list(input().split()) P list(input().split()) list input().split() ().split () input split enqueue(P[0], int(P[1])) enqueue P[0] P 0 int(P[1]) int P[1] P 1 elaps = 0 elaps 0 while head != tail:
    u,t = dequeue()
    c = min(q, t)
    t -= c
    elaps += c
    if t > 0:
        enqueue(u,t)
    else:
        print(u + " " + str(elaps)) head != tail head tail u,t = dequeue() u dequeue() dequeue t c = min(q, t) c min(q, t) min q t t -= c t c elaps += c elaps c if t > 0:
        enqueue(u,t)
    else:
        print(u + " " + str(elaps)) t > 0 t 0 enqueue(u,t) enqueue u t print(u + " " + str(elaps)) print u + " " + str(elaps) u + " " u " " str(elaps) str elaps t = dequeue() dequeue() t t -= c c t head = 0 0 head elaps = 0 0 elaps P = list(input().split()) list(input().split()) P def enqueue(u, t):
    global tail
    Q[tail] = [u, t]
    tail = (tail + 1) % MAX def enqueue(u, t):
    global tail
    Q[tail] = [u, t]
    tail = (tail + 1) % MAX enqueue n,q = map(int, input().split()) map(int, input().split()) n c = min(q, t) min(q, t) c def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) %MAX
    return [x,t] def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) %MAX
    return [x,t] dequeue MAX = n + 2 n + 2 MAX u,t = dequeue() dequeue() u Q = [0 for i in range(MAX)] [0 for i in range(MAX)] Q q = map(int, input().split()) map(int, input().split()) q tail = 0 0 tail elaps += c c elaps
n,q = map(int, input().split())
MAX = n + 2
Q = [0 for i in range(MAX)]
head = 0
tail = 0

def enqueue(u, t):
    global tail
    Q[tail] = [u, t]
    tail = (tail + 1) % MAX

def dequeue():
    global head
    x,t = Q[head]
    head = (head + 1) %MAX
    return [x,t]
for i in range(n):
    P = list(input().split())
    enqueue(P[0], int(P[1]))

elaps = 0
while head != tail:
    u,t = dequeue()
    c = min(q, t)
    t -= c
    elaps += c
    if t > 0:
        enqueue(u,t)
    else:
        print(u + " " + str(elaps))