Buggy python submission (verdict: Time Limit Exceeded):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=str(k).zfill(6)



import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))

Fixed submission:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = input().split()
    S=int(S)
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=k.zfill(6)

import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=str(k).zfill(6)



import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))

Fixed submission:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = input().split()
    S=int(S)
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=k.zfill(6)

import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])



import bisect

for i in inputs:
    P,S=i
    pref_str=str(P)
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_str.zfill(6)+city_str.zfill(6))

Fixed submission:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = input().split()
    S=int(S)
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=k.zfill(6)

import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])



import bisect

for i in inputs:
    P,S=i
    pref_str=str(P)
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_str.zfill(6)+city_str.zfill(6))

Fixed submission:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = input().split()
    S=int(S)
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=k.zfill(6)

import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])



import bisect

for i in inputs:
    P,S=i
    pref_str=str(P)
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_str.zfill(6)+city_str.zfill(6))

Fixed submission:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = input().split()
    S=int(S)
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=k.zfill(6)

import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))