a,b=map(int,input().split())
list=[[0 for i in range(2)] for j in range(a)]
for i in range(a):
    list[i]=input().split()
n=0
s=0
while n!=a:
    if int(list[n][1])>b:
        list[n][1]=int(list[n][1])-b
        list.append(list[n])
        list.pop(n)
        s+=b
    else:
        print(list[n][0],s+int(list[n][1]))
        s+=int(list[n][1])
        n+=1
 a,b=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b [0 for i in range(2)] for j in range(a) for j in range(a) j range(a) range a for j in range(a) [0 for i in range(2)] list=[[0 for i in range(2)] for j in range(a)] list [[0 for i in range(2)] for j in range(a)] for i in range(a):
    list[i]=input().split() i range(a) range a list[i]=input().split() list[i] list i input().split() ().split () input split n=0 n 0 s=0 s 0 while n!=a:
    if int(list[n][1])>b:
        list[n][1]=int(list[n][1])-b
        list.append(list[n])
        list.pop(n)
        s+=b
    else:
        print(list[n][0],s+int(list[n][1]))
        s+=int(list[n][1])
        n+=1 n!=a n a if int(list[n][1])>b:
        list[n][1]=int(list[n][1])-b
        list.append(list[n])
        list.pop(n)
        s+=b
    else:
        print(list[n][0],s+int(list[n][1]))
        s+=int(list[n][1])
        n+=1 int(list[n][1])>b int(list[n][1]) int list[n][1] [n] list n 1 b list[n][1]=int(list[n][1])-b list[n][1] [n] list n 1 int(list[n][1])-b int(list[n][1]) int list[n][1] [n] list n 1 b list.append(list[n]) list.append list append list[n] list n list.pop(n) list.pop list pop n s+=b s b print(list[n][0],s+int(list[n][1])) print list[n][0] [n] list n 0 s+int(list[n][1]) s int(list[n][1]) int list[n][1] [n] list n 1 s+=int(list[n][1]) s int(list[n][1]) int list[n][1] [n] list n 1 n+=1 n 1 s=0 0 s list=[[0 for i in range(2)] for j in range(a)] [[0 for i in range(2)] for j in range(a)] list n=0 0 n s+=b b s a,b=map(int,input().split()) map(int,input().split()) a n+=1 1 n b=map(int,input().split()) map(int,input().split()) b s+=int(list[n][1]) int(list[n][1]) s
a,b=map(int,input().split())
list=[[0 for i in range(2)] for j in range(a)]
for i in range(a):
    list[i]=input().split()
n=0
s=0
while n!=a:
    if int(list[n][1])>b:
        list[n][1]=int(list[n][1])-b
        list.append(list[n])
        list.pop(n)
        s+=b
    else:
        print(list[n][0],s+int(list[n][1]))
        s+=int(list[n][1])
        n+=1

