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

main :: IO ()
main = readContents 2 >>= main'
    where
        main' [[n, k], as] = print $ solve k as

solve :: Int -> [Int] -> Int
solve k as = sum $ map (xor res) as
    where
        res = traceShowId $ value bs
        bs = map (check . (2 ^)) es 
        es = dropWhile (ek <=) [40, 39..0]
            where
                ek = ceiling . logBase 2 $ fromIntegral k

        value = foldl' ff 0 . zip es
            where
                ff acc (e, b)
                    | b = acc + (2 ^ e)
                    | otherwise = acc

        check x = br $ foldl' ff (0, 0) as
            where
                br (a, b) = a > b 
                
                ff (a, b) y 
                    | x .&. y == 0 = (a + 1, b)
                    | otherwise = (a, b + 1)

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

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