import Control.Applicative ((<$>)) import Control.Monad (replicateM) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List import Data.Function (on, fix) import Data.Char (isSpace) main :: IO () main = do n <- getl (readi B.readInt) solve n <$> replicateM n (getl $ readil B.readInt) >>= mapM_ putStrLn solve :: Int -> [[Int]] -> [String] solve n = f1 . maximumBy (compare `on` snd) . zip [1..n] . map f2 where f1 (x, y) | 6 * y >= 3000000 = "YES" : replicate 6 (show x) | otherwise = ["NO"] f2 [g, d] = g - 30000 * d getl :: (ByteString -> a) -> IO a getl f = f <$> B.getLine readi :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> a readi f s = let Just (n, _) = f s in n readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')