Program So_du;
var x,n,m,y,i,j:int64;
f:text;
s:string;
begin
i:=1;
assign(f,'REMAINDER.TXT');rewrite(f);
while i<=15 do
begin
readln(x,n,m);
str(x,s); j:=1;
while j<=n do begin s:=s+s;inc(j); end;
val(s,y);
writeln(f,y mod m);
inc(i);
end;
close(f);
end.