n, q = map(int, input().split())
process = []
for _ in range(n):
    name, time = input().split()
    process.append([name, int(time)])
process.append([])

def reduce(index):
    left_time = process[index][1] - q
    return [process[index][0], left_time]

head = 0
tail = n
quene_len = len(process)
elapsed_time = 0

while head != tail:
    if process[head][1] > q:
        process[tail] = reduce(head)
        elapsed_time += q
        head = (head+1)%quene_len
        tail = (tail+1)%quene_len
    else:
        elapsed_time += process[head][1]
        print(process[head][0], elapsed_time)
        head = (head+1)%quene_len n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q process = [] process [] for _ in range(n):
    name, time = input().split()
    process.append([name, int(time)]) _ range(n) range n name, time = input().split() name input().split() ().split () input split time process.append([name, int(time)]) process.append process append [name, int(time)] name int(time) int time process.append([]) process.append process append [] def reduce(index):
    left_time = process[index][1] - q
    return [process[index][0], left_time] reduce left_time = process[index][1] - q left_time process[index][1] - q process[index][1] [index] process index 1 q return [process[index][0], left_time] [process[index][0], left_time] process[index][0] [index] process index 0 left_time index index head = 0 head 0 tail = n tail n quene_len = len(process) quene_len len(process) len process elapsed_time = 0 elapsed_time 0 while head != tail:
    if process[head][1] > q:
        process[tail] = reduce(head)
        elapsed_time += q
        head = (head+1)%quene_len
        tail = (tail+1)%quene_len
    else:
        elapsed_time += process[head][1]
        print(process[head][0], elapsed_time)
        head = (head+1)%quene_len head != tail head tail if process[head][1] > q:
        process[tail] = reduce(head)
        elapsed_time += q
        head = (head+1)%quene_len
        tail = (tail+1)%quene_len
    else:
        elapsed_time += process[head][1]
        print(process[head][0], elapsed_time)
        head = (head+1)%quene_len process[head][1] > q process[head][1] [head] process head 1 q process[tail] = reduce(head) process[tail] process tail reduce(head) reduce head elapsed_time += q elapsed_time q head = (head+1)%quene_len head (head+1)%quene_len head+1 head 1 quene_len tail = (tail+1)%quene_len tail (tail+1)%quene_len tail+1 tail 1 quene_len elapsed_time += process[head][1] elapsed_time process[head][1] [head] process head 1 print(process[head][0], elapsed_time) print process[head][0] [head] process head 0 elapsed_time head = (head+1)%quene_len head (head+1)%quene_len head+1 head 1 quene_len head = (head+1)%quene_len (head+1)%quene_len head head = 0 0 head quene_len = len(process) len(process) quene_len time = input().split() input().split() time elapsed_time = 0 0 elapsed_time elapsed_time += process[head][1] process[head][1] elapsed_time def reduce(index):
    left_time = process[index][1] - q
    return [process[index][0], left_time] def reduce(index):
    left_time = process[index][1] - q
    return [process[index][0], left_time] reduce process = [] [] process name, time = input().split() input().split() name q = map(int, input().split()) map(int, input().split()) q elapsed_time += q q elapsed_time tail = n n tail tail = (tail+1)%quene_len (tail+1)%quene_len tail head = (head+1)%quene_len (head+1)%quene_len head n, q = map(int, input().split()) map(int, input().split()) n
n, q = map(int, input().split())
process = []
for _ in range(n):
    name, time = input().split()
    process.append([name, int(time)])
process.append([])

def reduce(index):
    left_time = process[index][1] - q
    return [process[index][0], left_time]

head = 0
tail = n
quene_len = len(process)
elapsed_time = 0

while head != tail:
    if process[head][1] > q:
        process[tail] = reduce(head)
        elapsed_time += q
        head = (head+1)%quene_len
        tail = (tail+1)%quene_len
    else:
        elapsed_time += process[head][1]
        print(process[head][0], elapsed_time)
        head = (head+1)%quene_len
