{-# LANGUAGE ScopedTypeVariables #-}
import Data.List
import Control.Monad

modif::Int->String
modif i = let n =  length (show i) in (take (6-n) (repeat '0'))++(show i)

sort_sort::[(Int,Int)]->[(Int,Int)]
sort_sort = (map (\ ((i,p),n) -> (p,n)) ).
            (sortBy (\ ((i1,_),_) -> \ ((i2,_),_) -> compare i1 i2)).
            concat.
            (map ((\ l -> zip l [1..]).map (\(i,(p,_))->(i,p)))).
            (map (sortBy (\ (_,(_,y1)) -> \ (_,(_,y2)) -> compare y1 y2))).
            (groupBy (\ (_,(p1,_)) -> \ (_,(p2,_)) -> p1 == p2)).
            (sortBy (\ (_,(p1,_)) -> \ (_,(p2,_)) -> compare p1 p2)).
            (zip [(1::Int) ..])

solver::[(Int,Int)]->[String]
solver = (map (\(p,n) -> (modif p)++(modif n))).sort_sort

main::IO()
main=do
  nmc<-getLine
  let n:m:[]=map read (words nmc)
  dat<-forM [1..m] (\_-> do
                    py<-getLine
                    let p:y:[]= map read (words py)
                    return (p,y))
  forM_ (solver dat) (\ str -> do
                                putStr str
                                putStr "\n")