{-# LANGUAGE TupleSections #-}
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad.State (State, evalState, gets, modify)
import Data.Map.Strict (Map, lookup, insert, empty)
import Data.Maybe (maybe)
import Control.Monad

main :: IO ()
main = breads >>= main'
    where
        main' [d, g] = replicateM d breads >>= print . solve g

solve :: Int -> [[Int]] -> Int
solve g pcs = run calc . (g,) . map build $ zip pcs [1..]
    where
        build ([p, c], i) = A (p * 100 * i + c) p (replicate p (100 * i))

        calc f (r, A p c ps : xs)
            | r > 0 = minimum <$> sequence [(+ c) <$> f (r - p, xs), f (r, B (tail ps) : xs)]
            | otherwise = return 0
        calc f (r, B (p : ps) : xs)
            | r > 0 = minimum <$> sequence [succ <$> f (r - p, B ps : xs), f (r, xs)]
            | otherwise = return 0
        calc f (r, _ : xs)
            | r > 0 = f (r, xs)
            | otherwise = return 0 
        calc _ (r, _)
            | r > 0 = return 100000
            | otherwise = return 0

data K = A Int Int [Int] | B [Int]
    deriving (Show, Eq, Ord)

type Memoizer a b = a -> State (Map a b) b

run :: (Ord a) => (Memoizer a b -> Memoizer a b) -> a -> b
run f = flip evalState empty . memoizeFix f

memoizeFix :: (Ord a) => (Memoizer a b -> Memoizer a b) -> Memoizer a b
memoizeFix f x = gets (Data.Map.Strict.lookup x) >>= maybe (f (memoizeFix f) x >>= ((<$) <*> (modify . Data.Map.Strict.insert x))) return

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)