Buggy python submission (verdict: Time Limit Exceeded):
import collections as c
d=c.defaultdict(list)
d2=c.defaultdict(list)
a,b,*q=map(int,open(0).read().split())
for s in range(b):
    g,j=q[2*s],q[2*s+1]
    d[g].append(j)
    d[g]=sorted(d[g])
for t in d.keys():
    for k,v in enumerate(d[t]):
        d2[t].append((v,k+1))
#print(d2)
for s in range(b):
    g,j=q[2*s],q[2*s+1]
    for sss in d2[g]:
        if sss[0]==j:
            print('{:06d}'.format(g)+'{:06d}'.format(sss[1]))

Fixed submission:
a,b=map(int,input().split())
l=[]
for _ in range(b):
    c,d=map(int,input().split())
    l.append((c,d))
l2=sorted(sorted(l, key=lambda x:x[1]), key=lambda y:y[0])
m=1
count=0
dic={}
for t in l2:
    if t[0] !=m:
        m=t[0]
        count=1
    else:
        count+=1
    dic[t]=count
#print(dic)
for q in l:
    print('{:06d}'.format(q[0])+'{:06d}'.format(dic[q]))

Buggy python submission (verdict: Time Limit Exceeded):
import collections as c
d=c.defaultdict(list)
d2=c.defaultdict(list)
a,b,*q=map(int,open(0).read().split())
for s in range(b):
    g,j=q[2*s],q[2*s+1]
    d[g].append(j)
    d[g]=sorted(d[g])
for t in d.keys():
    for k,v in enumerate(d[t]):
        d2[t].append((v,k+1))
#print(d2)
for s in range(b):
    g,j=q[2*s],q[2*s+1]
    for sss in d2[g]:
        if sss[0]==j:
            print('{:06d}'.format(g)+'{:06d}'.format(sss[1]))

Fixed submission:
a,b=map(int,input().split())
l=[]
for _ in range(b):
    c,d=map(int,input().split())
    l.append((c,d))
l2=sorted(sorted(l, key=lambda x:x[1]), key=lambda y:y[0])
m=1
count=0
dic={}
for t in l2:
    if t[0] !=m:
        m=t[0]
        count=1
    else:
        count+=1
    dic[t]=count
#print(dic)
for q in l:
    print('{:06d}'.format(q[0])+'{:06d}'.format(dic[q]))

Buggy python submission (verdict: Time Limit Exceeded):
import collections as c
d=c.defaultdict(list)
d2=c.defaultdict(list)
a,b=map(int,input().split())
l=[]
for s in range(b):
    g,j=map(int,input().split())
    d[g].append(j)
    d[g]=sorted(d[g])
    l.append([g,j])
for t in d.keys():
    for k,v in enumerate(d[t]):
        d2[t].append([v,k+1])
for sss in l:
    for ttt in d2[sss[0]]:
        if ttt[0]==sss[1]:
            print('{:06d}'.format(sss[0])+'{:06d}'.format(ttt[1]))

Fixed submission:
a,b=map(int,input().split())
l=[]
for _ in range(b):
    c,d=map(int,input().split())
    l.append((c,d))
l2=sorted(sorted(l, key=lambda x:x[1]), key=lambda y:y[0])
m=1
count=0
dic={}
for t in l2:
    if t[0] !=m:
        m=t[0]
        count=1
    else:
        count+=1
    dic[t]=count
#print(dic)
for q in l:
    print('{:06d}'.format(q[0])+'{:06d}'.format(dic[q]))

Buggy python submission (verdict: Time Limit Exceeded):
import collections as c
d=c.defaultdict(list)
d2=c.defaultdict(list)
a,b=map(int,input().split())
l=[]
for s in range(b):
    g,j=map(int,input().split())
    d[g].append(j)
    l.append([g,j])
#print(d)
d3=c.defaultdict(list)
for k,v in d.items():
    d2[k]=sorted(v)
for t in d2.keys():
    for k,v in enumerate(d2[t]):
        d3[t].append([v,k+1])
#print(d3)
#print(l)
for sss in l:
    for ttt in d3[sss[0]]:
        if ttt[0]==sss[1]:
            print('{:06d}'.format(sss[0])+'{:06d}'.format(ttt[1]))
  #          print(sss[0],ttt[1])

Fixed submission:
a,b=map(int,input().split())
l=[]
for _ in range(b):
    c,d=map(int,input().split())
    l.append((c,d))
l2=sorted(sorted(l, key=lambda x:x[1]), key=lambda y:y[0])
m=1
count=0
dic={}
for t in l2:
    if t[0] !=m:
        m=t[0]
        count=1
    else:
        count+=1
    dic[t]=count
#print(dic)
for q in l:
    print('{:06d}'.format(q[0])+'{:06d}'.format(dic[q]))

Buggy python submission (verdict: Time Limit Exceeded):
import collections as c
d=c.defaultdict(list)
d2=c.defaultdict(list)
a,b=map(int,input().split())
l=[]
for s in range(b):
    g,j=map(int,input().split())
    d[g].append(j)
    l.append([g,j])
#print(d)
d3=c.defaultdict(list)
for k,v in d.items():
    d2[k]=sorted(v)
for t in d2.keys():
    for k,v in enumerate(d2[t]):
        d3[t].append([v,k+1])
#print(d3)
#print(l)
for sss in l:
    for ttt in d3[sss[0]]:
        if ttt[0]==sss[1]:
            print('{:06d}'.format(sss[0])+'{:06d}'.format(ttt[1]))
  #          print(sss[0],ttt[1])

Fixed submission:
a,b=map(int,input().split())
l=[]
for _ in range(b):
    c,d=map(int,input().split())
    l.append((c,d))
l2=sorted(sorted(l, key=lambda x:x[1]), key=lambda y:y[0])
m=1
count=0
dic={}
for t in l2:
    if t[0] !=m:
        m=t[0]
        count=1
    else:
        count+=1
    dic[t]=count
#print(dic)
for q in l:
    print('{:06d}'.format(q[0])+'{:06d}'.format(dic[q]))