Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
data=[]
p=[0]*n
y=[[] for _ in range(n)]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i])
    p[p_i-1]+=1
    y[p_i-1].append(y_i)
for i in range(n):
    y[i].sort()
for i in range(m):
    ans_p=data[i][0]
    ans_y=y[ans_p-1].index(data[i][1])+1
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
data=[]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i,i])
data.sort()
data.append([n+1,0,m])
buf=1
for i in range(m):
    data[i].append(buf)
    if data[i][0]==data[i+1][0]:
        buf+=1
    else:
        buf=1
data.sort(key=itemgetter(2))
for i in range(m):
    ans_p=data[i][0]
    ans_y=data[i][3]
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
data=[]
p=[0]*n
y=[[] for _ in range(n)]
q=[]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i])
    p[p_i-1]+=1
    y[p_i-1].append(y_i)
for i in range(n):
    if p[i]>1:
        y[i].sort()
for i in range(m):
    ans_p=data[i][0]
    ans_y=y[ans_p-1].index(data[i][1])+1
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
data=[]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i,i])
data.sort()
data.append([n+1,0,m])
buf=1
for i in range(m):
    data[i].append(buf)
    if data[i][0]==data[i+1][0]:
        buf+=1
    else:
        buf=1
data.sort(key=itemgetter(2))
for i in range(m):
    ans_p=data[i][0]
    ans_y=data[i][3]
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
data=[]
p=[0]*n
y=[[] for _ in range(n)]
q=[]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i])
    p[p_i-1]+=1
    y[p_i-1].append(y_i)
    if p_i-1 not in q:
        q.append(p_i-1)
for i in q:
    y[i].sort()
for i in range(m):
    ans_p=data[i][0]
    ans_y=y[ans_p-1].index(data[i][1])+1
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
data=[]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i,i])
data.sort()
data.append([n+1,0,m])
buf=1
for i in range(m):
    data[i].append(buf)
    if data[i][0]==data[i+1][0]:
        buf+=1
    else:
        buf=1
data.sort(key=itemgetter(2))
for i in range(m):
    ans_p=data[i][0]
    ans_y=data[i][3]
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
data=[]
p=[0]*n
y=[[] for _ in range(n)]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i])
    p[p_i-1]+=1
    y[p_i-1].append(y_i)
for i in range(n):
    if p[i]!=0:
        y[i].sort()
for i in range(m):
    ans_p=data[i][0]
    ans_y=y[ans_p-1].index(data[i][1])+1
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
data=[]
for i in range(m):
    p_i,y_i=map(int,input().split())
    data.append([p_i,y_i,i])
data.sort()
data.append([n+1,0,m])
buf=1
for i in range(m):
    data[i].append(buf)
    if data[i][0]==data[i+1][0]:
        buf+=1
    else:
        buf=1
data.sort(key=itemgetter(2))
for i in range(m):
    ans_p=data[i][0]
    ans_y=data[i][3]
    ans_p=(str(ans_p)).zfill(6)
    ans_y=(str(ans_y)).zfill(6)
    print(ans_p+ans_y)