($a,$b,$c,$d)=split$",<>;print $a*$b%$d*$c%$d