import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad 
import Data.Ord 

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

solve :: Int -> [[Int]] -> Int
solve h xs = an + calc (h - an * fa) bs
    where
        bs = sortBy (flip compare) . filter (> fa) $ fmap last xs
        fa = head $ maximumBy (\x y -> comparing head x y) xs
        bsum = sum bs
        (ar, am) = (h - bsum) `divMod` fa
        an
            | am > 0 = ar + 1
            | otherwise = ar
        calc r (y : ys)
            | r <= 0 = 0 
            | otherwise = 1 + calc (r - y) ys
        calc r _
            | r > 0 = h * 2
            | otherwise = 0

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)