n, k = gets.split.map(&:to_i)
name = []
time = []

n.times{|i|
    name[i], time[i] = gets.split
}

time = time.map(&:to_i)

t = 0

finished_name = []
finished_time = []

while name.length > 0
    if time[0] <= k
        finished_name.push(name[0])
        finished_time.push(t + time[0])
        t = t + time[0]
        name.shift
        time.shift
    else
        x = name.shift
        name.push(x)
        time[0] -= k
        x = time.shift
        time.push(x)
        t += k
    end
end

n.times{|i|
    printf("%s %d\n", finished_name[i], finished_time[i])
}
