Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
queue = []
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    if queue[0]["time"] <= q:
        t += queue[0]["time"]
        name = queue[0]["name"]
        queue = queue[1:]
        print("{} {}".format(name, t))
    else:
        queue = queue[1:] + \
            [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
        t += q



Fixed submission:
from collections import deque
n, q = map(int, input().split())
queue = deque()
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    head = queue.popleft()
    if head["time"] <= q:
        t += head["time"]
        name = head["name"]
        print("{} {}".format(name, t))
    else:
        queue.append({"name": head["name"], "time": head["time"] - q})
        t += q

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
queue = []
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    if queue[0]["time"] <= q:
        t += queue[0]["time"]
        name = queue[0]["name"]
        queue = queue[1:]
        print("{} {}".format(name, t))
    else:
        if len(queue) != 1:
            queue = queue[1:] + \
                [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
            t += q
        else:
            queue[0] = {"name": queue[0]["name"], "time": queue[0]["time"] - q}
            t += q



Fixed submission:
from collections import deque
n, q = map(int, input().split())
queue = deque()
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    head = queue.popleft()
    if head["time"] <= q:
        t += head["time"]
        name = head["name"]
        print("{} {}".format(name, t))
    else:
        queue.append({"name": head["name"], "time": head["time"] - q})
        t += q

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
queue = []
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    if queue[0]["time"] <= q:
        t += queue[0]["time"]
        name = queue[0]["name"]
        queue = queue[1:]
        print("{} {}".format(name, t))
    else:
        if len(queue) != 1:
            queue = queue[1:] + \
                [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
            t += q
        else:
            queue[0] = {"name": queue[0]["name"], "time": queue[0]["time"] - q}
            t += q



Fixed submission:
from collections import deque
n, q = map(int, input().split())
queue = deque()
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    head = queue.popleft()
    if head["time"] <= q:
        t += head["time"]
        name = head["name"]
        print("{} {}".format(name, t))
    else:
        queue.append({"name": head["name"], "time": head["time"] - q})
        t += q

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
queue = []
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    if queue[0]["time"] <= q:
        t += queue[0]["time"]
        name = queue[0]["name"]
        queue = queue[1:]
        print("{} {}".format(name, t))
    else:
        if len(queue) != 1:
            queue = queue[1:] + \
                [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
            t += q
        else:
            queue[0] = {"name": queue[0]["name"], "time": queue[0]["time"] - q}
            t += q



Fixed submission:
from collections import deque
n, q = map(int, input().split())
queue = deque()
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    head = queue.popleft()
    if head["time"] <= q:
        t += head["time"]
        name = head["name"]
        print("{} {}".format(name, t))
    else:
        queue.append({"name": head["name"], "time": head["time"] - q})
        t += q

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
queue = []
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    if queue[0]["time"] <= q:
        t += queue[0]["time"]
        name = queue[0]["name"]
        queue.remove(queue[0])
        print("{} {}".format(name, t))
    else:
        queue = queue[1:] + \
            [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
        t += q



Fixed submission:
from collections import deque
n, q = map(int, input().split())
queue = deque()
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    head = queue.popleft()
    if head["time"] <= q:
        t += head["time"]
        name = head["name"]
        print("{} {}".format(name, t))
    else:
        queue.append({"name": head["name"], "time": head["time"] - q})
        t += q

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
queue = []
min_time = 10000000
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
    min_time = min(min_time, int(time))
# print(min_time)
t = 0
if q < min_time:
    queue = [{"name": queue[i]["name"], "time":queue[i]["time"] - min_time}
             for i in range(n)]
    t = min_time * n
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    if queue[0]["time"] <= q:
        t += queue[0]["time"]
        name = queue[0]["name"]
        queue.remove(queue[0])
        print("{} {}".format(name, t))
    else:
        queue = queue[1:] + \
            [{"name": queue[0]["name"], "time":queue[0]["time"] - q}]
        t += q



Fixed submission:
from collections import deque
n, q = map(int, input().split())
queue = deque()
for i in range(n):
    name, time = input().split()
    queue.append({"name": name, "time": int(time)})
t = 0
while len(queue) != 0:
    #print([queue[i]["time"] for i in range(len(queue))])
    head = queue.popleft()
    if head["time"] <= q:
        t += head["time"]
        name = head["name"]
        print("{} {}".format(name, t))
    else:
        queue.append({"name": head["name"], "time": head["time"] - q})
        t += q