Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ls = [[] for _ in range(10**5)]
k = 0
di = [list(map(int,input().split())) for _ in range(m)]
for i in range(m):
    ls[di[i][0]-1].append(di[i][1])
    if di[i][0] > k:
        k = di[i][0]
for j in range(k):
    ls[j].sort()
for l in range(m): 
    p = str(10**12 + di[l][0]*(10**6) + ls[di[l][0]-1].index(di[l][1])+1)
    print(p[1:])


Fixed submission:
n,m = map(int,input().split())
ls = [[] for _ in range(n+1)]
di = []
for i in range(m):
    a,b = map(int,input().split())
    ls[a].append([b,i+1])
for j in range(n+1):
    if ls[j] != []:
        ls[j].sort(key=lambda x :x[0])
        for k in range(len(ls[j])):
            di.append([ls[j][k][1],str(10**12+j*10**6+k+1)[1:]])
di.sort(key=lambda x :x[0])
for l in range(m):
    print(di[l][1])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ls = [[0,0] for _ in range(m)]
di = [[] for _ in range(n)]
for k in range(m):
    c,d = map(int,input().split())
    ls[k][0],ls[k][1] = c,d
    di[c-1].append(d)
for i in range(n):
    di[i].sort()
for j in range(m):
    a,b = ls[j][0],ls[j][1]
    p = di[a-1].index(b)
    q = 10**12 + (a)*10**6 +(p+1)
    print(str(q)[1:])



Fixed submission:
n,m = map(int,input().split())
ls = [[] for _ in range(n+1)]
di = []
for i in range(m):
    a,b = map(int,input().split())
    ls[a].append([b,i+1])
for j in range(n+1):
    if ls[j] != []:
        ls[j].sort(key=lambda x :x[0])
        for k in range(len(ls[j])):
            di.append([ls[j][k][1],str(10**12+j*10**6+k+1)[1:]])
di.sort(key=lambda x :x[0])
for l in range(m):
    print(di[l][1])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
di = [0]*n
for i in range(n):
    new = [e[1] for e in ls if e[0] == i+1]
    new.sort()
    di[i] = new
for j in range(m):
    a,b = ls[j][0],ls[j][1]
    p = di[a-1].index(b)
    q = 10**12 + (a)*10**6 +(p+1)
    print(str(q)[1:])



Fixed submission:
n,m = map(int,input().split())
ls = [[] for _ in range(n+1)]
di = []
for i in range(m):
    a,b = map(int,input().split())
    ls[a].append([b,i+1])
for j in range(n+1):
    if ls[j] != []:
        ls[j].sort(key=lambda x :x[0])
        for k in range(len(ls[j])):
            di.append([ls[j][k][1],str(10**12+j*10**6+k+1)[1:]])
di.sort(key=lambda x :x[0])
for l in range(m):
    print(di[l][1])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
di = [[] for _ in range(n)]
for i in range(m):
    di[ls[i][0]-1].append(ls[i][1])
    di[ls[i][0]-1].sort()
for k in range(m):
    a = di[ls[k][0]-1].index(ls[k][1])
    q = 10**12 + (ls[k][0])*10**6 +(a+1)
    print(str(q)[1:])
    


Fixed submission:
n,m = map(int,input().split())
ls = [[] for _ in range(n+1)]
di = []
for i in range(m):
    a,b = map(int,input().split())
    ls[a].append([b,i+1])
for j in range(n+1):
    if ls[j] != []:
        ls[j].sort(key=lambda x :x[0])
        for k in range(len(ls[j])):
            di.append([ls[j][k][1],str(10**12+j*10**6+k+1)[1:]])
di.sort(key=lambda x :x[0])
for l in range(m):
    print(di[l][1])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
di = [[] for _ in range(n)]
for i in range(m):
    di[ls[i][0]-1].append(ls[i][1])
    di[ls[i][0]-1].sort()
for k in range(m):
    a = di[ls[k][0]-1].index(ls[k][1])
    print(str(ls[k][0]).rjust(6,"0")+str(a+1).rjust(6,"0"))
    


Fixed submission:
n,m = map(int,input().split())
ls = [[] for _ in range(n+1)]
di = []
for i in range(m):
    a,b = map(int,input().split())
    ls[a].append([b,i+1])
for j in range(n+1):
    if ls[j] != []:
        ls[j].sort(key=lambda x :x[0])
        for k in range(len(ls[j])):
            di.append([ls[j][k][1],str(10**12+j*10**6+k+1)[1:]])
di.sort(key=lambda x :x[0])
for l in range(m):
    print(di[l][1])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
di = [[] for _ in range(n)]
for i in range(m):
    di[ls[i][0]-1].append(ls[i][1])
for j in range(n):
    di[j].sort()
for k in range(m):
    a = di[ls[k][0]-1].index(ls[k][1])
    print(str(ls[k][0]).rjust(6,"0")+str(a+1).rjust(6,"0"))
    


Fixed submission:
n,m = map(int,input().split())
ls = [[] for _ in range(n+1)]
di = []
for i in range(m):
    a,b = map(int,input().split())
    ls[a].append([b,i+1])
for j in range(n+1):
    if ls[j] != []:
        ls[j].sort(key=lambda x :x[0])
        for k in range(len(ls[j])):
            di.append([ls[j][k][1],str(10**12+j*10**6+k+1)[1:]])
di.sort(key=lambda x :x[0])
for l in range(m):
    print(di[l][1])