n,q = map(int,input().split())
name = []
time = []
for i in range(n):
    tmp = input().split()
    name.append(str(tmp[0]))
    time.append(int(tmp[1]))
    
total = 0
result = []
while True:
    try:
        if time[0] > q:
            total += q
            time[0] = time[0] - q
            tmp = time.pop(0)
            time.append(tmp)
            tmp = name.pop(0)
            name.append(tmp)
        elif q >= time[0] and time[0] > 0:
            total += time[0]
            time.pop(0)
            a = name.pop(0)
            print(a,total)
        else:
            break
    except:
        break n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q name = [] name [] time = [] time [] for i in range(n):
    tmp = input().split()
    name.append(str(tmp[0]))
    time.append(int(tmp[1]))
     i range(n) range n tmp = input().split() tmp input().split() ().split () input split name.append(str(tmp[0])) name.append name append str(tmp[0]) str tmp[0] tmp 0 time.append(int(tmp[1])) time.append time append int(tmp[1]) int tmp[1] tmp 1 total = 0 total 0 result = [] result [] while True:
    try:
        if time[0] > q:
            total += q
            time[0] = time[0] - q
            tmp = time.pop(0)
            time.append(tmp)
            tmp = name.pop(0)
            name.append(tmp)
        elif q >= time[0] and time[0] > 0:
            total += time[0]
            time.pop(0)
            a = name.pop(0)
            print(a,total)
        else:
            break
    except:
        break True try:
        if time[0] > q:
            total += q
            time[0] = time[0] - q
            tmp = time.pop(0)
            time.append(tmp)
            tmp = name.pop(0)
            name.append(tmp)
        elif q >= time[0] and time[0] > 0:
            total += time[0]
            time.pop(0)
            a = name.pop(0)
            print(a,total)
        else:
            break
    except:
        break except:
        break break if time[0] > q:
            total += q
            time[0] = time[0] - q
            tmp = time.pop(0)
            time.append(tmp)
            tmp = name.pop(0)
            name.append(tmp)
        elif q >= time[0] and time[0] > 0:
            total += time[0]
            time.pop(0)
            a = name.pop(0)
            print(a,total)
        else:
            break
     time[0] > q time[0] time 0 q total += q total q time[0] = time[0] - q time[0] time 0 time[0] - q time[0] time 0 q tmp = time.pop(0) tmp time.pop(0) time.pop time pop 0 time.append(tmp) time.append time append tmp tmp = name.pop(0) tmp name.pop(0) name.pop name pop 0 name.append(tmp) name.append name append tmp elif q >= time[0] and time[0] > 0:
            total += time[0]
            time.pop(0)
            a = name.pop(0)
            print(a,total)
         q >= time[0] and time[0] > 0 q >= time[0] q time[0] time 0 time[0] > 0 time[0] time 0 0 total += time[0] total time[0] time 0 time.pop(0) time.pop time pop 0 a = name.pop(0) a name.pop(0) name.pop name pop 0 print(a,total) print a total break n,q = map(int,input().split()) map(int,input().split()) n total += q q total total += time[0] time[0] total time = [] [] time total = 0 0 total tmp = name.pop(0) name.pop(0) tmp result = [] [] result name = [] [] name tmp = time.pop(0) time.pop(0) tmp a = name.pop(0) name.pop(0) a q = map(int,input().split()) map(int,input().split()) q tmp = input().split() input().split() tmp
n,q = map(int,input().split())
name = []
time = []
for i in range(n):
    tmp = input().split()
    name.append(str(tmp[0]))
    time.append(int(tmp[1]))
    
total = 0
result = []
while True:
    try:
        if time[0] > q:
            total += q
            time[0] = time[0] - q
            tmp = time.pop(0)
            time.append(tmp)
            tmp = name.pop(0)
            name.append(tmp)
        elif q >= time[0] and time[0] > 0:
            total += time[0]
            time.pop(0)
            a = name.pop(0)
            print(a,total)
        else:
            break
    except:
        break