Problem:
 Score: 300 points    Problem Statement In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.  City i is established in year Y_i and belongs to Prefecture P_i .  You can assume that there are no multiple cities that are established in the same year.  It is decided to allocate a 12 -digit ID number to each city.  If City i is the x -th established city among the cities that belong to Prefecture i , the first six digits of the ID number of City i is P_i , and the last six digits of the ID number is x .  Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.  Find the ID numbers for all the cities.  Note that there can be a prefecture with no cities.      Constraints  1 \leq N \leq 10^5  1 \leq M \leq 10^5  1 \leq P_i \leq N  1 \leq Y_i \leq 10^9  Y_i are all different.  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  P_1  Y_1  :  P_M  Y_M       Output Print the ID numbers for all the cities, in ascending order of indices (City 1 , City 2 , ... ).        Sample Input 1 2 3
1 32
2 63
1 12      Sample Output 1 000001000002
000002000001
000001000001   As City 1 is the second established city among the cities that belong to Prefecture 1 , its ID number is 000001000002 .  As City 2 is the first established city among the cities that belong to Prefecture 2 , its ID number is 000002000001 .  As City 3 is the first established city among the cities that belong to Prefecture 1 , its ID number is 000001000001 .        Sample Input 2 2 3
2 55
2 77
2 99      Sample Output 2 000002000001
000002000002
000002000003

Solution (Python):
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')

Solution (Python):
N, M = map(int, input().split())
city = []
for i in range(M):
  P, Y = map(int, input().split())
  city.append([P, Y, i])
id = [''] * M

city.sort(key = lambda x: (x[0], x[1]))
prev_P = 0
count = 0
for i in city:
  if prev_P == i[0]:
    count += 1
  else:
    count = 1
  id[i[2]] = str(i[0]).zfill(6) + str(count).zfill(6)
  prev_P = i[0]

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

Solution (Python):
N,M = map(int,input().split())
py_list = []
d = dict()
for i in range(M):
    p,y = map(int,input().split())
    py_list.append([p,y])
py_sorted =  sorted(py_list)
p_temp = py_sorted[0][0]
count = 1
for p,y in py_sorted:
    if p_temp != p:
        p_temp = p
        count = 1
    d[(p,y)] = count
    count += 1

for i in range(M):
    s = d[(py_list[i][0],py_list[i][-1])]
    s = str(s)
    ss = str(py_list[i][0]).zfill(6) + s.zfill(6)
    print(ss.strip())

Solution (Python):
n, m = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(m)]
sPY = sorted(PY, key=lambda x:(x[0], x[1]))

ans = {}
key, cnt = 1, 1
for p, y in sPY:
    if p != key:
        key = p
        cnt = 1
    ans[y] = cnt
    cnt += 1

for p, y in PY:
    a = str(p).zfill(6)
    b = str(ans[y]).zfill(6)
    print("{}{}".format(a, b))

Solution (Python):
N, M = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(M)]
 
now = 0
num = 0
d = dict()
for p, y in sorted(data):
    if now != p:
        now = p
        num = 1
    d[(p,y)] = num
    num += 1
 
for p, y in data:
    print('{:06d}{:06d}'.format(p, d[(p,y)]))

Solution (Python):
n, m = map(int, input().split())
a = []
for i in range(m):
	a.append([int(n) for n in input().split()])
	a[i].append(i)
a = sorted(a)
b = []
counter = 0
counter1 = 1
for i in range(m):
	c = ""
	if a[i][0] < 100000:
		getlen = len(str(a[i][0]))
		c = "0" * (6 - getlen) + str(a[i][0])
	else:
		c = str(a[i][0])
	if i == 0:
		c += "000001"
		counter = a[0][0]
	elif a[i][0] == counter:
		getlen = len(str(counter1 + 1))
		c += "0" * (6 - getlen) + str(counter1 + 1)
		counter1 += 1
	else:
		counter1 = 1
		c += "000001"
		counter = a[i][0]
	a[i].append(c)

for i in range(m):
	a[i][2], a[i][0] = a[i][0], a[i][2]
a = sorted(a)
for i in range(m):
	print(a[i][3])

Solution (Python):
N, M = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(M)]

now = 0
num = 0
d = dict()
for p, y in sorted(data):
    if now != p:
        now = p
        num = 1
    d[(p,y)] = num
    num += 1

for p, y in data:
    print('{:06d}{:06d}'.format(p, d[(p,y)]))

Solution (Python):
N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]
sPY = sorted(PY, key=lambda py: (py[0],py[1]))

i = 1
bp = 1
d = {}
for p, y in sPY:
    if p != bp:
        i = 1
        bp = p
    d[y] = i
    i += 1

for p, y in PY:
    i = d[y]
    print("{0:06}{1:06}".format(p, i))

Solution (Python):
N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]
sPY = sorted(PY, key=lambda py: (py[0],py[1]))

i = 1
bp = 1
d = {}
for p, y in sPY:
    if p != bp:
        i = 1
        bp = p
    d[y] = i
    i += 1

for p, y in PY:
    print("{0:06}{1:06}".format(p, d[y]))

Solution (Python):
N, M = map(int, input().split())
pyi = []
exists = [0] * N
for i in range(M):
    p, y = map(int, input().split())
    pyi.append([p, y, i])
pyi.sort(key = lambda x: x[1])
iid = []
for i in range(M):
    p = pyi[i][0]
    div = pyi[i][2]
    exists[p - 1] += 1
    iid.append([div, str(p).zfill(6)+str(exists[p - 1]).zfill(6)])
iid.sort()
for i in range(M):
    print(iid[i][1])

Solution (Python):
n, m = list(map(int, input().split()))
p_li = []
y_li = []
for i in range(m):
    p, y = list(map(int, input().split()))
    p_li.append(p)
    y_li.append(y)
num = list(range(m))
zip_li = zip(p_li, y_li, num)
from operator import itemgetter
zip_li = sorted(zip_li, key=itemgetter(1))
p_li, y_li, num = zip(*zip_li)
ans = []
f_num = [0 for i in range(n)]
for p in p_li:
    p -= 1
    f_num[p] += 1
    f_n = f_num[p]
    p+=1
    ans.append(str(p).zfill(6) + str(f_n).zfill(6))
zip_li = zip(num, ans)
zip_li = sorted(zip_li, key=itemgetter(0))
num, ans = zip(*zip_li)
for i in ans:
    print(i)

Solution (Python):
def generate_id(p, x):
    return str(p).zfill(6) + str(x).zfill(6)

N, M = map(int, input().split())

A = []
B = {}
C = {}

for _ in range(M):
    a = tuple(map(int, input().split()))
    A.append(a)

    if a[0] in B:
        t = B[a[0]]
        t.append(a[1])
        B[a[0]] = t
    else:
        B[a[0]] = [a[1]]

for k, vs in B.items():
    vs = sorted(vs)
    for i, v in enumerate(vs):
        C[(k, v)] = i + 1

for a in A:
    print(generate_id(a[0], C[a]))

Solution (Python):
N, M = map(int, input().split())
P = {}
for i in range(1, M+1):
    _p, _y = map(int, input().split())
    if _p not in P: 
        P[_p] = []
    P[_p].append((i, _y))


numbers = {}

for _p in P:
    for j, t in enumerate(sorted(P[_p], key=lambda x: x[1])):
        numbers[t[0]] = "{:06d}{:06d}".format(_p, j+1)

for i in range(1, M+1):
    print(numbers[i])

Solution (Python):
import sys
from operator import itemgetter as ig
input=sys.stdin.readline

m,n=map(int,input().split())
dt=[]
for i in range(n):
    p,y = map(int, input().split())
    dt+=[[i,p,y,0]]
dt.sort(key=ig(1,2))
pi=1
prep=0
for x in dt:
    if prep==x[1]:
        pi+=1
    else:
        pi=1
    x[3]=pi
    prep=x[1]
dt.sort()
for x in dt:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Solution (Python):
import sys
input=sys.stdin.readline

m,n=map(int,input().split())
dt=[]
for i in range(n):
    p,y = map(int, input().split())
    dt+=[[i,p,y,0]]
dt.sort(key=lambda x:(x[1],x[2]))
pi=1
prep=0
for x in dt:
    if prep==x[1]:
        pi+=1
    else:
        pi=1
    x[3]=pi
    prep=x[1]
dt.sort()
for x in dt:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Solution (Python):
N, M = map(int, input().split())
p = [list(map(int, input().split())) + [i] for i in range(M)]
p.sort()
i = 0
for n in range(1, N + 1):
    count = 1
    while not(i >= M or p[i][0] != n):
        p[i] += [str(n).zfill(6) + str(count).zfill(6)]
        i += 1
        count += 1
p.sort(key=lambda x: x[2])
for a in p:
    print(a[3])

Solution (Python):
pref_num, city_num = map(int, input().split())
py = sorted([list(map(int, input().split())) + [i] for i in range(city_num)], key=lambda py: py[1])

city_num_in_prefs = [0 for _ in range(pref_num)]

city_nums = []
for pref, year, i in py:
    city_num_in_prefs[pref-1] += 1
    city_num = "{:06}{:06}".format(pref, city_num_in_prefs[pref-1])
    city_nums.append([city_num, i])

city_nums.sort(key=lambda x: x[1])
for num, index in city_nums:
    print(num)

Solution (Python):
m,n=map(int,input().split())
dt=[]
for i in range(n):
    p,y = map(int, input().split())
    dt+=[[i,p,y,0]]
dt.sort(key=lambda x:(x[1],x[2]))
pi=1
prep=0
for x in dt:
    if prep==x[1]:
        pi+=1
    else:
        pi=1
    x[3]=pi
    prep=x[1]
dt.sort()
for x in dt:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Solution (Python):
from operator import itemgetter

N, M = map(int, input().split())

ci = []
pi = [0] * N
for i in range(M):
    ci.append([i] + list(map(int, input().split())))

ci.sort(key=itemgetter(1,2))
for c in ci:
    pi[c[1]-1] += 1
    prestr = str(c[1]).zfill(6)
    bhstr = str(pi[c[1]-1]).zfill(6)
    c.append(''.join([prestr, bhstr]))

ci.sort()
for c in ci:
    print(c[3])

Solution (Python):

import sys


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    tmp = []
    for i in range(M):
        p = P[i]
        y = Y[i]
        tmp.append([i, p, y, ''])
    tmp.sort(key=lambda x: x[2])
    count = [0] * (N + 1)
    for t in tmp:
        p = t[1]
        count[p] += 1
        t[3] = '%06d%06d' % (p, count[p])
    tmp.sort(key=lambda x: x[0])
    for t in tmp:
        print(t[3])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    P = [int()] * (M)  
    Y = [int()] * (M)  
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]

sPY = sorted(PY, key=lambda py: (py[0], py[1]))

i = 1
bp = 1
d = {}
for p, y in sPY:
    if p != bp:
        i = 1
        bp = p
    d[(p, y)] = i
    i += 1

for p, y in PY:
    i = d[(p, y)]
    print("{0:06}{1:06}".format(p, i))

Solution (Python):
from collections import defaultdict

N,M = map(int,input().split())
question = []
number = {}
counts = defaultdict(int)
for i in range(M):
    city,value = map(int,input().split())
    question.append([i,city,value])
sorted_question = sorted(question,key=lambda x: x[2])
for i,city,value in sorted_question:
    counts[city] += 1
    number[i] = "{:06}{:06}".format(city,counts[city])
for i in range(M):
    print(number[i])

Solution (Python):
from collections import defaultdict
N, M = map(int, input().split())

counts = defaultdict(int)
numbers = {}

cities = []
for i in range(M):
    p, y = map(int, input().split())
    cities.append([i, p, y])

sorted_cities = sorted(cities, key=lambda x: x[2])
for city in sorted_cities:
    i, p, y = city
    counts[p] += 1
    numbers[i] = '{:06}{:06}'.format(p, counts[p])

for city in cities:
    print(numbers[city[0]])

Solution (Python):
N,M=map(int,input().split())
a=[[i]+list(map(int,input().split())) for i in range(M)]
a.sort(key=lambda x:(x[1],x[2]))

j=0
for i in range(M):
    if j!=a[i][1]:
        j=a[i][1]
        k=1
    s=format(a[i][1],'0>6') + format(k,'0>6')
    a[i].append(s)
    k+=1

a.sort()
for i in range(M):
    print(a[i][3])

Solution (Python):
from bisect import bisect_right
n, m = map(int, input().split())
p = []
y = []
d = {i + 1: [] for i in range(n)}
for i in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
    d[p_].append(y_)
for i in d.keys():
    d[i] = sorted(d[i])
for i in range(m):
    print('{:06d}{:06d}'.format(p[i], bisect_right(d[p[i]], y[i])))

Solution (Python):
import numpy as np
from bisect import bisect_right


n, m = map(int, input().split())
p = []
y = []
d = {i + 1: [] for i in range(n)}



for i in range(m):
    p_, y_ = map(int, input().split())
    
    p.append(p_)
    y.append(y_)
    d[p_].append(y_)
for i in d.keys():
    d[i] = sorted(d[i])
for i in range(m):
    
    print('{:06d}{:06d}'.format(p[i], bisect_right(d[p[i]], y[i])))

Solution (Python):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
P_Y = [[int(_) for _ in input().split()] for _ in range(M)]
datalist = []

for i, j in enumerate(P_Y):
    datalist.append([i, j[0], j[1], 0])

datalist = sorted(datalist, key=lambda x: (x[1], x[2]))
num = 1
city = datalist[0][1]
datalist[0][3] = num

for i in range(1, M):
    if datalist[i][1] == datalist[i-1][1]:
        num += 1
        datalist[i][3] = num
    else:
        num = 1
        datalist[i][3] = num

datalist = sorted(datalist, key=lambda x: x[0])
for i in datalist:
    print(str(i[1]).zfill(6) + str(i[3]).zfill(6))

Solution (Python):
from sys import stdin
N,M=[int(x) for x in stdin.readline().rstrip().split()]
data=[ [] for _ in range(N)]
for i in range(M):
    P,Y=[int(x) for x in stdin.readline().rstrip().split()]
    data[P-1].append((Y,i))
ans=[0]*(M)
for ind_pre,j in enumerate(data):
    for ind_cit,k in enumerate(sorted(j)):
        ans[k[1]] = str(ind_pre+1).zfill(6) + str(ind_cit+1).zfill(6)
for l in ans:
  print(l)

Solution (Python):
from operator import attrgetter
class City:
    def __init__(self, city, pref, year):
        self.city = city
        self.pref = pref
        self.year = year
        self.number = 0

def main():
    N, M = map(int, input().split())
    prefcount = [0] * (N + 1)
    PY = [City(0, 0, 0)]
    for i in range(M):
        P, Y = map(int, input().split())
        PY.append(City(i + 1, P, Y))
    PY.sort(key=attrgetter("year"))
    for i in PY:
        i.number = str(i.pref * 1000000 + (prefcount[i.pref] + 1)).zfill(12)
        prefcount[i.pref] += 1
    PY.sort(key=attrgetter("city"))
    for i in range(1, M + 1):
        print(PY[i].number)
main()

Solution (Python):
import sys
input = sys.stdin.readline
import bisect as bs
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str(bs.bisect_left(dic[P_X[i][0]], P_X[i][1]) + 1).zfill(6))

Solution (Python):
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for i in range(M):
  L[i].append(i)
cnt = [0]*N
L = sorted(L, key = lambda x:x[1])
for i in range(M):
  L[i].append(cnt[L[i][0]-1])
  cnt[L[i][0]-1] += 1
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  ID = str(L[i][0]).zfill(6)+str(L[i][3]+1).zfill(6)
  print(ID)

Solution (Python):

from operator import itemgetter

N,M = map(int,input().split())
ｌ = []
for i in range(M):
    array = [i, 0, 0, '']
    array[1], array[2] = map(int, input().split())
    l.append(array)
tmp = 0 


l = sorted(l, key=itemgetter(1,2))

for ctr in range(M):
    if l[ctr-1][1] != l[ctr][1]:
        tmp = 0
    tmp += 1
    l[ctr][3] = str(l[ctr][1]).zfill(6) + str(tmp).zfill(6)
l = sorted(l, key=itemgetter(0))

for ctr in range(M):
    print(l[ctr][3])

Solution (Python):



n,m=map(int,input().split())

y=[]

py=[[]]*m




for i in range (n):
    y.append([])
for i in range(m):
    py[i]=list(map(int,input().split()))
    y[py[i][0]-1].append(py[i][1])
for i in range(n):
    y[i].sort()


d_y={}
for i in range(n):
    for j in range(len(y[i])):
        d_y[y[i][j]]=j+1
for i in range(m):
    if py[i][0]<10:
        print("00000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif  py[i][0]<100:
        print("0000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<1000:
        print("000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<10000:
        print("00"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<100000:
        print("0"+str(py[i][0]*10**6+d_y[py[i][1]]))
    else:
        print(str(py[i][0]*10**6+d_y[py[i][1]]))

Solution (Python):
N,M = map(int, input().split())
c = [0 for i in range(M)]
for i in range(M):
    p,y = map(int, input().split())
    c[i] = [i,p,y]
c = sorted(c, key = lambda x: x[2])

l = [1 for i in range(N)]
for i in c:
    i.append(l[i[1]-1])
    l[i[1]-1] += 1

c = sorted(c, key=lambda x:x[0])
for i in c:
    print(str(i[1]).zfill(6) + str(i[3]).zfill(6))

Solution (Python):
n, m = map(int, input().split())
buf = [None] * m
cnt = {k: [] for k in range(n+1)}
for i in range(m):
  p, y = map(int, input().split())
  cnt[p].append((y, i))
for p, l in cnt.items():
  if not l:
    continue
  l.sort()
  for j, (y,i) in enumerate(l):
    buf[i] = "{:06d}{:06d}".format(p, j+1)
print("\n".join(buf))

Solution (Python):
from operator import itemgetter

n,m = map(int,input().split())
py = []
pyy = []

npy = []

for i in range(m):

    pyy=list(map(int,input().split()))
    pyy.append(i)
    py.append(pyy)

py.sort(key=itemgetter(0,1))


num = 1

npy.append([str(10**12+py[0][0]*(10**6)+num)[1:13],py[0][2]])


for i in range(m-1):
    if py[i+1][0] == py[i][0]:
        num = num + 1
        npy.append([str(10**12+py[i+1][0]*(10**6)+num)[1:13],py[i+1][2]])
    else:
        num = 1
        npy.append([str(10**12+py[i+1][0]*(10**6)+num)[1:13],py[i+1][2]])

npy.sort(key=itemgetter(1))

for j in range(m):
    print(npy[j][0])

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')



N, M = 0, 0
P, Y = [], []


def set_inputs():
    global N, M, P, Y
    N, M = get_li()
    P, Y = get_data(M, [int, int])
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    prefecture = defaultdict(list)
    lst = [""] * M
    for i, (p, y) in enumerate(zip(P, Y)):
        prefecture[p].append((i, y))
    for k in prefecture.keys():
        prefecture[k].sort(key=operator.itemgetter(1))
        for i, (n, y) in enumerate(prefecture[k]):
            lst[n] = "{:06d}{:06d}".format(k, i + 1)
    for v in lst:
        print(v)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
L = [[i] + list(map(int, input().split()))+[0] for i in range(M)]
L.sort(key=lambda x: (x[1], x[2]))
c = 1
d = 0
for i in range(M):
    if d == L[i][1]:
        c += 1
        L[i][3] = c
    else:
        L[i][3] = 1
        c = 1
        d = L[i][1]
L.sort()
[print(str(L[i][1]).zfill(6) + str(L[i][3]).zfill(6)) for i in range(M)]

Solution (Python):
N, M = map(int, input().split())
tp = []
L = []
for i in range(M):
    tp = [i] + list(map(int, input().split())) + [0]
    L.append(tp)
L.sort(key=lambda x: (x[1], x[2]))
c = 1
d = 0
for i in range(M):
    if d == L[i][1]:
        c += 1
        L[i][3] = c
    else:
        L[i][3] = 1
        c = 1
        d = L[i][1]
L.sort()
[print(str(L[i][1]).zfill(6) + str(L[i][3]).zfill(6)) for i in range(M)]

Solution (Python):
N, M = map(int,input().split())
tp = [0,0,0,""]
L = []
for i in range(M):
    tp = [i] +list(map(int,input().split())) +[0]
    L.append(tp)

L.sort(key=lambda x:(x[1],x[2]))
c = 1
d = 0
for i in range(M):
    if d == L[i][1]:
        c += 1
        L[i][3] = c
    else:
        L[i][3] = 1
        c = 1
        d = L[i][1]



L.sort()

for i in range(M):
    print(str(L[i][1]).zfill(6)+str(L[i][3]).zfill(6))

Solution (Python):
n,m=map(int,input().split())
l=[]
grp=[[] for i in range(n)]
for i in range(m):
    l.append(list(map(int,input().split())))
    grp[l[i][0]-1].append(l[i][1])
ydic={}
for i in range(n):
    grp[i].sort()
    for j in range(len(grp[i])):
        ydic[grp[i][j]]=j+1
for i in l:
    print(str(i[0]).zfill(6)+str(ydic[i[1]]).zfill(6))

Solution (Python):
N, M = map(int, input().split())
id_ = [1] * (N+1)
city = []
for i in range(M):
    P, Y = map(int, input().split())
    city.append([P, Y, i, 0])

city.sort(key=lambda t: t[1])
for i in range(len(city)):
    city[i][3] = str(city[i][0]).zfill(6) + str(id_[city[i][0]]).zfill(6)
    id_[city[i][0]] += 1

city.sort(key=lambda c: c[2])

for c in city:
    print(c[3])

Solution (Python):
N,M = map(int,input().split(' '))


l = []
for i in range(M):
	P,Y = map(int,input().split(' '))
	l.append([P,Y,i])

l.sort(key=lambda x:x[1])

num = [1]*N

for s in l:
	s[1] = num[s[0]-1]
	num[s[0]-1]+=1

l.sort(key=lambda x:x[2])

for s,n,_ in l:
	print(str(s).zfill(6)+str(n).zfill(6))

Solution (Python):
N, M = map(int, input().split())
A = [''] * M
P = [[] for _ in range(N)]
for i in range(M):
    pi, yi = map(int, input().split())
    P[pi-1].append((yi, i))

for j, pref in enumerate(P):
    pref = sorted(pref, key=lambda x: x[0])
    for k, (yi, i) in enumerate(pref):
        A[i] += str(j+1).zfill(6) + str(k+1).zfill(6)
        
for a in A:
    print(a)

Solution (Python):
n,m = map(int,input().split())
PY = [list(map(int,input().split()))+[0] for i in range(m)]
X = sorted(PY,key = lambda x:x[1])
city = {}
for x in X:
    p = x[0]
    y = x[1]
    if p in city:
        city[p] += 1
    else:
        city[p] = 1
    x[2] = city[p]
for p,y,z in PY:
    print(str(p).zfill(6)+str(z).zfill(6))

Solution (Python):
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])

city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))

Solution (Python):
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])

city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))

Solution (Python):
n, m = map(int, input().split())

cities = sorted(([list(map(int, input().split())) + [i] for i in range(m)]))
pref = cities[0]
counter = 1
for city in cities:
    if pref != city[0]:
        counter = 1
    pref = city[0]
    rank = counter
    number = str(pref).zfill(6) + str(rank).zfill(6)
    city.append(number)
    counter += 1
for i in sorted(cities, key=lambda x: x[2]):
    print(i[3])

Solution (Python):
import sys
import bisect
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0] for i in range(10**5+1)]
for i in l:
  s[i[0]].append(i[1])
for i in range(len(s)):
  s[i].sort()
for i in l:
  print('{:06}{:06}'.format(i[0],bisect.bisect_left(s[i[0]],i[1])))

Solution (Python):
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])
city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))

Solution (Python):
n,m = map(int,input().split())
py = []
for i in range(m):
    p,y = map(int,input().split())
    py.append([p,y,i])
ans = ['0'] * m
py.sort()

j = 0
for i in range(m):
    if j!= py[i][0]:
        j = py[i][0]
        c=1
    ans[py[i][2]] = str(py[i][0]).zfill(6) + str(c).zfill(6)
    c += 1
for i in range(m):
    print(ans[i])

Solution (Python):
n, m = map(int, input().split())
l = [[] for i in range(n+1)]

for i in range(m):
  p, y = map(int, input().split())
  l[p].append([p, y, i])

for i in range(1, len(l)):

  temp = sorted(l[i], key=lambda x: x[1])

  for j in range(len(temp)):
    temp[j] = [str(temp[j][0]).zfill(6), str(j+1).zfill(6), temp[j][2]]
  
  l[i] = temp

ans = []

for item in l:
  ans += item

for item in sorted(ans, key=lambda x: x[2]):
  print(item[0] + item[1])

Solution (Python):
from collections import defaultdict, OrderedDict

n, m = [int(x) for x in raw_input().split()]
r = defaultdict(list)
s = OrderedDict()
for i in range(m):
	p, y = [int(x) for x in raw_input().split()]
	s[(p, y)] = 0
	r[p].append(y)
for p, v in r.iteritems():
	v.sort()
	for i in range(len(v)):
		s[(p, v[i])] = i + 1

for t in s:
	print "%06d%06d"% (t[0], s[t])

Solution (Python):


n, m = [int(x) for x in raw_input().split()]
ret = []
pos = {}
pp = []
for i in xrange(m):
	p, y = [int(x) for x in raw_input().split()]
	ret.append((p, y, i))
	pp.append(p)

ret.sort()

last = 0
rank = 0
for p, y, i in ret:
	if last != p:
		rank = 0
		last = p
	rank += 1
	pos[i] = rank

for i in xrange(m):
	print '%06d%06d' % (pp[i], pos[i])

Solution (Python):
N, M = list(map(int, input().split()))
P, Y = [], []
for _ in range(M):
  p, y = list(map(int, input().split()))
  P.append(p)
  Y.append(y)
  
num = ['']*M

pref_dict={i:[] for i in range(1,N+1)}

for i, c in enumerate(zip(P,Y)):
  pref_dict[c[0]].append([i+1, c[1]]) 
  
for p, l in pref_dict.items():
  for i, c in enumerate(sorted(l, key=lambda x:x[1])):
    num[c[0]-1] = '{:06}{:06}'.format(p,i+1)
        
for n in num:
  print(n)

Solution (Python):
n,m = map(int, input().split())
py=[]
for i in range(m):
    p,y=map(int, input().split())
    py.append([i,p,y])

py.sort(key=lambda x:(x[1],x[2]))
sorted_py = py
num = 1
prev_p = str(sorted_py[0][1])
for i in range(m):
    p = str(sorted_py[i][1])
    if prev_p != p:
        num = 1
        prev_p = p
    str_num = str(num)
    if len(p)!=6:
        p = '0'*(6-len(p))+p
    if len(str_num)!=6:
        str_num = '0'*(6-len(str_num))+str_num
    sorted_py[i].append(p+str_num)
    num+=1
sorted_py.sort()
for i in range(m):
    print(sorted_py[i][3])

Solution (Python):
n, m = map(int, input().split())

N=[1]*n
D=[]
for i in range(m):
    p, y = map(int, input().split())
    D.append([i,p,y])

D.sort(key= lambda x:x[2] )
for i in range(m):
    D[i].append(N[D[i][1]-1])
    N[D[i][1]-1]+=1

D.sort()
for d in D:
    print("{:0>6}{:0>6}".format(d[1],d[3]))

Solution (Python):
N,M = map(int,input().split())
list = [[] for i in range(N)]

for i in range(M):
    p,y = map(int,input().split())
    list[p-1].append((y,i))

ans = [None]*M

for j,list_p in enumerate(list):
    list_p.sort()
    for k,(p,y) in enumerate(list_p):
        ans[y] = '%06d%06d' % (j+1,k+1)

print(*ans,sep='\n')

Solution (Python):
N,M = map(int,input().split())
list = [[] for i in range(N)]

for i in range(M):
    j,k = map(int,input().split())
    list[j-1].append((k,i))

ans = [None]*M

for i,j in enumerate(list):
    j.sort()
    for k,(l,m) in enumerate(j):
        ans[m] = "%06d%06d" % (i+1,k+1)

print(*ans, sep='\n')

Solution (Python):
import numpy as np
N, M = map(int,input().split())
P_Y_list = np.array([input().split() for _ in range(0, M)], dtype='int')
counts = (np.zeros(N+1)).astype(int)
id_list = []

sort_ind = np.argsort(P_Y_list[:,1])
sorted_P_Y = P_Y_list[sort_ind]

for p, y in sorted_P_Y:
    counts[p] += 1
    id_list.append(str(p).zfill(6) + str(counts[p]).zfill(6))
id_list = np.array(id_list)
id_list = id_list[np.argsort(sort_ind)]
for id in id_list:
    print(id)

Solution (Python):
n, m = map(int, input().split())
pyidx = []
for i in range(m):
    py_tmp = list(map(int, (input()).split() + [str(i)]))
    pyidx += [py_tmp]

pyidx = sorted(pyidx, key=lambda x: x[1])

counter = [1] * n

ans = []
for i, pyx in enumerate(pyidx):
    p, y, idx = pyx[0], pyx[1], pyx[2]
    x_new = counter[p-1]
    counter[p-1] += 1
    ans.append([str(p).zfill(6) + str(x_new).zfill(6), idx])

ans = sorted(ans, key=lambda x: x[1])
for i in ans:
    print(i[0])

Solution (Python):
n,m = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(m)]
d = [list() for _ in range(n)]
dic = [dict() for _ in range(n)]
for x in l:
  d[x[0]-1].append(x[1])
for r in range(n):
  d[r].sort()
  dic[r] = dict(zip(d[r],range(1,len(d[r])+1)))
for x in l:
  p = x[0]
  y = dic[x[0]-1][x[1]]
  print("{:06}{:06}".format(p,y))

Solution (Python):
N,M = list(map(int,input().split()))
City = [[i]+list(map(int,input().split())) +[""] for i in range(M)]

City2 = sorted(City,key = lambda x:(x[1],x[2]))
x = 1
cur_P = 0
for i,row in enumerate(City2):
    if cur_P != row[1]:
        x = 1
        cur_P = row[1]
    else:
        x += 1
    City2[i][3] = ("000000"+str(cur_P))[-6:] + ("000000"+str(x))[-6:]
for row in City:
    print(row[3])

Solution (Python):
debug = 0
"""
N: state num
M: city num
"""


if debug:
    N = 2
    m = 10
else:
    (N, M) = list(map(int, input().split()))

if debug:
    p_y_list = [
        [1, 30]
        ,[1, 20]
        ,[1, 10]
        ,[1, 3]
        ,[2, 63]
        ,[2, 33]
        ,[2, 23]
        ,[3, 21]
        ,[3, 7]
    ]

city_id_list = []
for num, z in enumerate(range(M)):

    
    if not debug:
        (P, Y) = list(map(int, input().split()))

    city_id_list.append([Y, P, num])
    
city_id_list = sorted( city_id_list, key= lambda x: x[0])

state_cnt = {}
tmp_list = []
for (Y, P, num) in city_id_list:
    
    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)
    
    tmp_list.append([num, tmp_id])
    
for cid in sorted(tmp_list, key=lambda x: x[0]):
    print(cid[1])

Solution (Python):
N, M = map ( int, input ( ).split ( ) )

lists = [ ]

for i in range ( M ):
    lists.append ( list ( map ( int, input ( ).split ( ) ) ) + [ i ] )

lists.sort ( key=lambda x: x[ 1 ] )
lists.sort ( key=lambda x: x[ 0 ] )

bef = 0
state = 0
retstr = ''
triple = [ ]
for i in lists:
    if (i[ 0 ] != bef):
        bef = i[ 0 ]
        state = 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
    else:
        state += 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
 
triple.sort ( key=lambda x: x[ 2 ] )
for i in triple:
    print ( i[ 3 ] )

Solution (Python):
from collections import defaultdict
N, M = map(int, input().split())
py = [list(map(int, input().split())) for i in range(M)]
PY = sorted(py, key=lambda x: x[1])
pydict = defaultdict(lambda: 0)
ans = {}
for i in PY:
    pydict[i[0]] += 1
    ans[str(i[0]) + str(i[1])] = "{:0=6}".format(i[0]) + "{:0=6}".format(pydict.get(i[0]))

for i in py:
    print(ans.get(str(i[0]) + str(i[1])))