Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N,M = map(int,input().split())
	array = []
	array2 = [[] for i in range(N)]
	for i in range(M):
	    array.append(list(map(int,input().split())))
	    array2[array[i][0]-1].append(array[i][1])

	for i in range(N):
	    array2[i] = sorted(array2[i])

	for i in range(M):
	    pnum = str(array[i][0])
	    cnum = str(array2[array[i][0]-1].index(array[i][1])+1)
	    print('0'*(6-len(pnum)) + pnum + '0'*(6-len(cnum)) + cnum)
main()

Fixed submission:
N,M = map(int,input().split())
PY = []
for i in range(M):
    P,Y = map(int,input().split())
    PY.append([P,Y,i])

PY.sort()
ans = [0 for i in range(M)]
count = 0
old = 0
for j in range(M):
    p,y,inum = PY[j]
    if old == p:
        pnum = p
        cnum = count
    else:
        old = p
        count = 1
        pnum = p
        cnum = 1

    count += 1
    pnum = str(pnum)
    cnum = str(cnum)
    ans[inum] = '0'*(6-len(pnum)) + pnum + '0'*(6-len(cnum)) + cnum

for i in range(M):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
array = []
array2 = [[] for i in range(N)]
for i in range(M):
    array.append(list(map(int,input().split())))
    array2[array[i][0]-1].append(array[i][1])

for i in range(N):
    array2[i] = sorted(array2[i])

for i in range(M):
    pnum = str(array[i][0])
    cnum = str(array2[array[i][0]-1].index(array[i][1])+1)
    print('0'*(6-len(pnum)) + pnum + '0'*(6-len(cnum)) + cnum)


Fixed submission:
N,M = map(int,input().split())
PY = []
for i in range(M):
    P,Y = map(int,input().split())
    PY.append([P,Y,i])

PY.sort()
ans = [0 for i in range(M)]
count = 0
old = 0
for j in range(M):
    p,y,inum = PY[j]
    if old == p:
        pnum = p
        cnum = count
    else:
        old = p
        count = 1
        pnum = p
        cnum = 1

    count += 1
    pnum = str(pnum)
    cnum = str(cnum)
    ans[inum] = '0'*(6-len(pnum)) + pnum + '0'*(6-len(cnum)) + cnum

for i in range(M):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
array=[]
for i in range(M):
    P,Y = list(map(int,input().split()))
    array.append([P,Y])
array2 = sorted(array)
arraysorted1 = []
j = 1
k = 0
while j != N+1:
    array3=[]
    while k <= M-1:
        if array2[k][0] == j:
            array3.append(array2[k][1])
        k += 1
    array3= sorted(array3)
    arraysorted1.append(array3)
    k = len(arraysorted1[j-1])
    j += 1
for n in range(M):
    for m in range(len(arraysorted1[array[n][0]-1])):
        if array[n] == [array[n][0], arraysorted1[array[n][0]-1][m]]:
            lenf = 6-len(str(array[n][0]))
            lenl = 6-len(str(m+1))
            
            print('0'*lenf +str(array[n][0])+'0'*lenl + str(m+1))


Fixed submission:
N,M = map(int,input().split())
PY = []
for i in range(M):
    P,Y = map(int,input().split())
    PY.append([P,Y,i])

PY.sort()
ans = [0 for i in range(M)]
count = 0
old = 0
for j in range(M):
    p,y,inum = PY[j]
    if old == p:
        pnum = p
        cnum = count
    else:
        old = p
        count = 1
        pnum = p
        cnum = 1

    count += 1
    pnum = str(pnum)
    cnum = str(cnum)
    ans[inum] = '0'*(6-len(pnum)) + pnum + '0'*(6-len(cnum)) + cnum

for i in range(M):
    print(ans[i])