def ALDS1_3B():
    n, q = map(int, input().split())
    PQ = [[l[0], int(l[1])] for l in  [input().split() for i in range(n)]  ]
    times = 0
    while PQ:
        p = PQ.pop(0)
        if p[1] <= q:
            times += p[1]
            print('%s %d' %(p[0], times))
        else:
            times += q
            PQ.append([p[0], p[1]-q])


if __name__ == '__main__':
    ALDS1_3B() def ALDS1_3B():
    n, q = map(int, input().split())
    PQ = [[l[0], int(l[1])] for l in  [input().split() for i in range(n)]  ]
    times = 0
    while PQ:
        p = PQ.pop(0)
        if p[1] <= q:
            times += p[1]
            print('%s %d' %(p[0], times))
        else:
            times += q
            PQ.append([p[0], p[1]-q]) ALDS1_3B n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q [l[0], int(l[1])] for l in  [input().split() for i in range(n)] for l in  [input().split() for i in range(n)] l [input().split() for i in range(n)] for l in  [input().split() for i in range(n)] [l[0], int(l[1])] l[0] l 0 int(l[1]) int l[1] l 1 PQ = [[l[0], int(l[1])] for l in  [input().split() for i in range(n)]  ] PQ [[l[0], int(l[1])] for l in  [input().split() for i in range(n)]  ] times = 0 times 0 while PQ:
        p = PQ.pop(0)
        if p[1] <= q:
            times += p[1]
            print('%s %d' %(p[0], times))
        else:
            times += q
            PQ.append([p[0], p[1]-q]) PQ p = PQ.pop(0) p PQ.pop(0) PQ.pop PQ pop 0 if p[1] <= q:
            times += p[1]
            print('%s %d' %(p[0], times))
        else:
            times += q
            PQ.append([p[0], p[1]-q]) p[1] <= q p[1] p 1 q times += p[1] times p[1] p 1 print('%s %d' %(p[0], times)) print '%s %d' %(p[0], times) '%s %d' (p[0], times) p[0] p 0 times times += q times q PQ.append([p[0], p[1]-q]) PQ.append PQ append [p[0], p[1]-q] p[0] p 0 p[1]-q p[1] p 1 q if __name__ == '__main__':
    ALDS1_3B() __name__ == '__main__' __name__ '__main__' ALDS1_3B() ALDS1_3B def ALDS1_3B():
    n, q = map(int, input().split())
    PQ = [[l[0], int(l[1])] for l in  [input().split() for i in range(n)]  ]
    times = 0
    while PQ:
        p = PQ.pop(0)
        if p[1] <= q:
            times += p[1]
            print('%s %d' %(p[0], times))
        else:
            times += q
            PQ.append([p[0], p[1]-q]) def ALDS1_3B():
    n, q = map(int, input().split())
    PQ = [[l[0], int(l[1])] for l in  [input().split() for i in range(n)]  ]
    times = 0
    while PQ:
        p = PQ.pop(0)
        if p[1] <= q:
            times += p[1]
            print('%s %d' %(p[0], times))
        else:
            times += q
            PQ.append([p[0], p[1]-q]) ALDS1_3B
def ALDS1_3B():
    n, q = map(int, input().split())
    PQ = [[l[0], int(l[1])] for l in  [input().split() for i in range(n)]  ]
    times = 0
    while PQ:
        p = PQ.pop(0)
        if p[1] <= q:
            times += p[1]
            print('%s %d' %(p[0], times))
        else:
            times += q
            PQ.append([p[0], p[1]-q])


if __name__ == '__main__':
    ALDS1_3B()