import Data.List

main = do
[l,a,b,n] <- map read.words <$> getLine
let f x = if x == 1 then [a] else f (x-1) ++ [a + b * (x-1)]
let g x = if x == [] then [] else [show $ head x] ++ g ( tail x)
print $ mod (read (intercalate "" $ g (f l))) n