Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis)
i = 1
flag = 0
for _ in lis_sort:
    if flag != _[0]:
        flag = _[0]
        i = 1
    ans_lis[lis.index(_)] = str(i)
    i += 1
for x,y in zip(lis,ans_lis):
    print('0'*(6-len(str(x[0]))),x[0],'0'*(6-len(y)),y,sep='')



Fixed submission:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis)
i = 1
flag = 0
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_lis[lis.index(lis_sort[_])] = str(i)
    i += 1
for x,y in zip(lis,ans_lis):
    print('0'*(6-len(str(x[0]))),x[0],'0'*(6-len(y)),y,sep='')

Fixed submission:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis)
i = 1
flag = 0
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_lis[lis.index(lis_sort[_])] = str(i)
    i += 1
for x,y in zip(lis,ans_beh_lis):
    print('0'*(6-len(str(x[0]))),x[0],'0'*(6-len(y)),y,sep='')



Fixed submission:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
flag = 0
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_pra_lis = []
ans_beh_lis = [0] * M
lis_sort = sorted(lis)
for _ in lis:
    s = str(_[0])
    ans_pra_lis.append(s)
i = 1
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_beh_lis[lis.index(lis_sort[_])] = str(i)
    i += 1
for x,y in zip(ans_pra_lis,ans_beh_lis):
    print('0'*(6-len(x)),x,'0'*(6-len(y)),y,sep='')



Fixed submission:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
flag = 0
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_pra_lis = []
ans_beh_lis = [0] * M
lis_sort = sorted(lis)
for _ in lis:
    s = str(0)*(6-len(str(_[0]))) + str(_[0])
    ans_pra_lis.append(s)
i = 1
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_beh_lis[lis.index(lis_sort[_])] = str(0)*(6-len(str(i))) + str(i)
    i += 1
for x,y in zip(ans_pra_lis,ans_beh_lis):
    print(x,end = '')
    print(y)

Fixed submission:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')