Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = [None] * M
    pref_dec = {}
    for m in range(M):
        p, y = map(int, input().split())
        city_list[m] = (p, y)
        if p not in pref_dec:
            pref_dec[p] = []
        pref_dec[p].append(y)

    for p in set(pref_dec.keys()):
        pref_dec[p].sort()

    for m in range(M):
        p_id = city_list[m][0]
        y_id = pref_dec[p_id].index(city_list[m][1]) + 1
        print(str(p_id).zfill(6) + str(y_id).zfill(6))


Fixed submission:
#coding:utf-8
#参考：https://beta.atcoder.jp/contests/abc113/submissions/3806710


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        p, y = map(int, input().split())
        city_list.append([i, p, y])

    city_count = {}
    order_dic = {}
    for i, p, y in sorted(city_list, key = lambda x: x[2]):
        if not p in city_count:
            city_count[p] = 0
        city_count[p] += 1
        order_dic[i, p] = city_count[p]

    for i, p, y in city_list:
        print("{:06}{:06}".format(p, order_dic[i,p]))

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    pref_dec = {}
    for m in range(M):
        p, y = map(int, input().split())
        city_list.append((p, y))
        if p not in pref_dec:
            pref_dec[p] = []
        pref_dec[p].append(y)

    for p in set(pref_dec.keys()):
        pref_dec[p].sort()

    for m in range(M):
        p_id = city_list[m][0]
        y_id = pref_dec[p_id].index(city_list[m][1]) + 1
        print(str(p_id).zfill(6) + str(y_id).zfill(6))


Fixed submission:
#coding:utf-8
#参考：https://beta.atcoder.jp/contests/abc113/submissions/3806710


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        p, y = map(int, input().split())
        city_list.append([i, p, y])

    city_count = {}
    order_dic = {}
    for i, p, y in sorted(city_list, key = lambda x: x[2]):
        if not p in city_count:
            city_count[p] = 0
        city_count[p] += 1
        order_dic[i, p] = city_count[p]

    for i, p, y in city_list:
        print("{:06}{:06}".format(p, order_dic[i,p]))

Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    pref_dec = {}
    for m in range(M):
        p, y = map(int, input().split())
        city_list.append((p, y))
        if p not in pref_dec:
            pref_dec[p] = []
        pref_dec[p].append(y)

    for p in pref_dec.keys():
        pref_dec[p].sort()

    for m in range(M):
        p_id = city_list[m][0]
        y_id = pref_dec[p_id].index(city_list[m][1]) + 1
        print(str(p_id).zfill(6) + str(y_id).zfill(6))


Fixed submission:
#coding:utf-8
#参考：https://beta.atcoder.jp/contests/abc113/submissions/3806710


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        p, y = map(int, input().split())
        city_list.append([i, p, y])

    city_count = {}
    order_dic = {}
    for i, p, y in sorted(city_list, key = lambda x: x[2]):
        if not p in city_count:
            city_count[p] = 0
        city_count[p] += 1
        order_dic[i, p] = city_count[p]

    for i, p, y in city_list:
        print("{:06}{:06}".format(p, order_dic[i,p]))