N, qms = map(int, input().split())

raw_proc = [input() for i in range(N)]
queue = [{} for i in range(N+1)]
for i in range(N):
    name, time = raw_proc[i].split()
    time = int(time)
    queue[i] = {"name": name, "time": time}

def enque(tail, p):
    queue[tail] = p
    tail = (tail+1) % (N+1)
    return tail

def deque(head):
    proc = queue[head]
    head = (head+1) % (N+1)
    return proc, head


if __name__ == '__main__':
    head = 0
    tail = N
    total_time = 0
    while head != tail:
        p, head = deque(head)
        t = min(qms, p["time"])
        p["time"] = p["time"] - t
        total_time += t
        if p["time"] > 0:
            tail = enque(tail, p)
        else:
            print("{} {}".format(p["name"], total_time)) N, qms = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split qms input() for i in range(N) for i in range(N) i range(N) range N for i in range(N) input() input raw_proc = [input() for i in range(N)] raw_proc [input() for i in range(N)] {} for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) {} queue = [{} for i in range(N+1)] queue [{} for i in range(N+1)] for i in range(N):
    name, time = raw_proc[i].split()
    time = int(time)
    queue[i] = {"name": name, "time": time} i range(N) range N name, time = raw_proc[i].split() name raw_proc[i].split() [i].split [i] raw_proc i split time time = int(time) time int(time) int time queue[i] = {"name": name, "time": time} queue[i] queue i {"name": name, "time": time} "name" "name" name "time" "time" time def enque(tail, p):
    queue[tail] = p
    tail = (tail+1) % (N+1)
    return tail enque queue[tail] = p queue[tail] queue tail p tail = (tail+1) % (N+1) tail (tail+1) % (N+1) tail+1 tail 1 N+1 N 1 return tail tail tail tail p p def deque(head):
    proc = queue[head]
    head = (head+1) % (N+1)
    return proc, head deque proc = queue[head] proc queue[head] queue head head = (head+1) % (N+1) head (head+1) % (N+1) head+1 head 1 N+1 N 1 return proc, head return proc, head proc head head head if __name__ == '__main__':
    head = 0
    tail = N
    total_time = 0
    while head != tail:
        p, head = deque(head)
        t = min(qms, p["time"])
        p["time"] = p["time"] - t
        total_time += t
        if p["time"] > 0:
            tail = enque(tail, p)
        else:
            print("{} {}".format(p["name"], total_time)) __name__ == '__main__' __name__ '__main__' head = 0 head 0 tail = N tail N total_time = 0 total_time 0 while head != tail:
        p, head = deque(head)
        t = min(qms, p["time"])
        p["time"] = p["time"] - t
        total_time += t
        if p["time"] > 0:
            tail = enque(tail, p)
        else:
            print("{} {}".format(p["name"], total_time)) head != tail head tail p, head = deque(head) p deque(head) deque head head t = min(qms, p["time"]) t min(qms, p["time"]) min qms p["time"] p "time" p["time"] = p["time"] - t p["time"] p "time" p["time"] - t p["time"] p "time" t total_time += t total_time t if p["time"] > 0:
            tail = enque(tail, p)
        else:
            print("{} {}".format(p["name"], total_time)) p["time"] > 0 p["time"] p "time" 0 tail = enque(tail, p) tail enque(tail, p) enque tail p print("{} {}".format(p["name"], total_time)) print "{} {}".format(p["name"], total_time) "{} {}".format "{} {}" format p["name"] p "name" total_time time = int(time) int(time) time def deque(head):
    proc = queue[head]
    head = (head+1) % (N+1)
    return proc, head def deque(head):
    proc = queue[head]
    head = (head+1) % (N+1)
    return proc, head deque tail = N N tail total_time += t t total_time raw_proc = [input() for i in range(N)] [input() for i in range(N)] raw_proc head = 0 0 head tail = enque(tail, p) enque(tail, p) tail queue = [{} for i in range(N+1)] [{} for i in range(N+1)] queue def enque(tail, p):
    queue[tail] = p
    tail = (tail+1) % (N+1)
    return tail def enque(tail, p):
    queue[tail] = p
    tail = (tail+1) % (N+1)
    return tail enque head = deque(head) deque(head) head name, time = raw_proc[i].split() raw_proc[i].split() name total_time = 0 0 total_time N, qms = map(int, input().split()) map(int, input().split()) N p, head = deque(head) deque(head) p t = min(qms, p["time"]) min(qms, p["time"]) t time = raw_proc[i].split() raw_proc[i].split() time qms = map(int, input().split()) map(int, input().split()) qms
N, qms = map(int, input().split())

raw_proc = [input() for i in range(N)]
queue = [{} for i in range(N+1)]
for i in range(N):
    name, time = raw_proc[i].split()
    time = int(time)
    queue[i] = {"name": name, "time": time}

def enque(tail, p):
    queue[tail] = p
    tail = (tail+1) % (N+1)
    return tail

def deque(head):
    proc = queue[head]
    head = (head+1) % (N+1)
    return proc, head


if __name__ == '__main__':
    head = 0
    tail = N
    total_time = 0
    while head != tail:
        p, head = deque(head)
        t = min(qms, p["time"])
        p["time"] = p["time"] - t
        total_time += t
        if p["time"] > 0:
            tail = enque(tail, p)
        else:
            print("{} {}".format(p["name"], total_time))
