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

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

solve :: Int -> Int -> [[Int]] -> Int 
solve n c xvs = max (count gs bs) $ count rgs rbs
    where
        rxvs = map (\[x, v] -> [c - x, v]) $ reverse xvs

        scanVss = scanl (\acc [_, v] -> acc + v) 0
        vss = scanVss xvs
        rvss = scanVss rxvs
        gs = zip3 [0..] vss . (0 :) $ map head xvs
        rgs = zip3 [0..] rvss . (0 :) $ map head rxvs
        scanBs = reverse . scanl (\acc (_, v, x) -> max acc $ v - x) 0 . tail 
        bs = scanBs rgs
        rbs = scanBs gs

        count xs = maximum . map mf . zip xs
            where
                mf ((_, v, x), mv) = max (v - x) $ v - 2 * x + mv

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine