Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque


def main():
    n, m = map(int, input().split())
    lines = sys.stdin.readlines()

    cities = {}
    mem_city = deque()
    for i in range(m):
        p, y = map(int, lines[i].split())
        mem_city.append((p, y))
        if p in cities:
            cities[p].append(y)
        else:
            cities[p] = [y]
    # print(cities)
    for key in cities:
        cities[key].sort()
    # print(cities)

    outputs = [None] * m
    for iter, p in enumerate(mem_city):
        idx = cities[p[0]].index(p[1]) + 1
        outputs[iter] = "{:06d}{:06d}".format(p[0], idx)

    for output in outputs:
        print(output)
    return


main()

Fixed submission:
import sys

def main():
    n, m = map(int, input().split())
    lines = sys.stdin.readlines()

    cities = {}
    for i in range(m):
        p, y = map(int, lines[i].split())
        if p in cities:
            cities[p].append((i, y))
        else:
            cities[p] = [(i, y)]

    outputs = [None] * m
    for pref, city_list in cities.items():
        city_list.sort(key=lambda x: x[1])
        #print(pref, city_list)
        city_no = 1
        for city in city_list:
            outputs[city[0]] = "{:06d}{:06d}".format(pref, city_no)
            city_no += 1

    for output in outputs:
        print(output)
    return


main()

Buggy python submission (verdict: Runtime Error):
import sys
def main():
    lines = sys.stdin.readlines()
    plist = [0] * 100000

    n, m = map(int, lines[0].split())
    cities={}
    for i in range(1, m+1):
        p, y = map(int, lines[i].split())
        plist[i-1] = p
        if p in cities:
            idx=0
            for item in cities[p]:
                if item[0] > y:
                    item[1] += 1
                else:
                    idx += 1
            cities[p].append([y, idx])
            pass
        else:
            cities[p] = [[y, 0]]

    for p in plist[:n+1]:
        #print(p, cities[p])
        print("{:06d}{:06d}".format(p, cities[p][0][1]+1))
        del cities[p][0]
    return

main()

Fixed submission:
import sys

def main():
    n, m = map(int, input().split())
    lines = sys.stdin.readlines()

    cities = {}
    for i in range(m):
        p, y = map(int, lines[i].split())
        if p in cities:
            cities[p].append((i, y))
        else:
            cities[p] = [(i, y)]

    outputs = [None] * m
    for pref, city_list in cities.items():
        city_list.sort(key=lambda x: x[1])
        #print(pref, city_list)
        city_no = 1
        for city in city_list:
            outputs[city[0]] = "{:06d}{:06d}".format(pref, city_no)
            city_no += 1

    for output in outputs:
        print(output)
    return


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
def main():
    lines = sys.stdin.readlines()
    n, m = map(int, lines[0].split())
    cities={}
    mem_city = deque()
    for i in range(1, m+1):
        p, y = map(int, lines[i].split())
        mem_city.append((p, y))
        if p in cities:
            cities[p].append(y)
        else:
            cities[p] = [y]
    #print(cities)
    for key in cities:
        cities[key].sort()
    #print(cities)

    for p, y in mem_city:
        idx = cities[p].index(y) + 1
        print("{:06d}{:06d}".format(p, idx))
    return

main()

Fixed submission:
import sys

def main():
    n, m = map(int, input().split())
    lines = sys.stdin.readlines()

    cities = {}
    for i in range(m):
        p, y = map(int, lines[i].split())
        if p in cities:
            cities[p].append((i, y))
        else:
            cities[p] = [(i, y)]

    outputs = [None] * m
    for pref, city_list in cities.items():
        city_list.sort(key=lambda x: x[1])
        #print(pref, city_list)
        city_no = 1
        for city in city_list:
            outputs[city[0]] = "{:06d}{:06d}".format(pref, city_no)
            city_no += 1

    for output in outputs:
        print(output)
    return


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    cities={}
    mem_city=[]
    for i in range(m):
        p, y = map(int, input().split())
        mem_city.append((p, y))
        if p in cities:
            cities[p].append(y)
        else:
            cities[p] = [y]
    #print(cities)
    for key in cities:
        cities[key].sort()
    #print(cities)

    for p, y in mem_city:
        idx = cities[p].index(y) + 1
        print("{:06d}{:06d}".format(p,idx))
    return

main()

Fixed submission:
import sys

def main():
    n, m = map(int, input().split())
    lines = sys.stdin.readlines()

    cities = {}
    for i in range(m):
        p, y = map(int, lines[i].split())
        if p in cities:
            cities[p].append((i, y))
        else:
            cities[p] = [(i, y)]

    outputs = [None] * m
    for pref, city_list in cities.items():
        city_list.sort(key=lambda x: x[1])
        #print(pref, city_list)
        city_no = 1
        for city in city_list:
            outputs[city[0]] = "{:06d}{:06d}".format(pref, city_no)
            city_no += 1

    for output in outputs:
        print(output)
    return


main()