import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [n, x] = count n x
    where
        count i j 
            | i == 0 && j == 0 = 0
            | i == 0 = 1
            | j < 2 = 0
            | j < l + 2 = count (i - 1) j
            | otherwise = 1 + p + count (i - 1) (min l $ j - 2 - l)
            where
                (l, p) = lps V.! (i - 1)

        lps = V.fromList lenPads

        lenPads = (1, 1) : build 1 lenPads
            where
                build c ((l, p) : xs)
                    | c > n = []
                    | otherwise = (3 + 2 * l, 1 + 2 * p) : build (c + 1) xs


readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine