import Control.Arrow
import Data.List

main :: IO ()
main = interact $ unlines . map (show' . uncurry era_name) . read' . lines
 where
  read' ("0 0":_) = []
  read' (nq:xs) = (db, map read qs') : read' xs'
   where
    [n,q] = map read (words nq)
    ((db',qs'),xs') = first (splitAt n) (splitAt (n+q) xs)
    db = map ((\[e,ey,wy] -> ((e, read ey), read wy)) . words) db'
  show' = init . unlines . map (maybe "Unknown" (\(e,ey) -> e ++ " " ++ show ey))

era_name :: [((String,Int),Int)] -> [Int] -> [Maybe (String,Int)]
era_name db qs = map (query (map period db)) qs

period :: ((String,Int),Int) -> (String, (Int,Int))
period ((e,ey),wy) = (e, (wy-ey+1,wy))

query :: [(String, (Int,Int))] -> Int -> Maybe (String,Int)
query db q = do
 (e,(wy1,wy2)) <- find (\(_,(wy1,wy2)) -> elem q [wy1..wy2]) db
 return (e, q-wy1+1)