var a,b,c,s,p,i,j,cnt,kk:longint;
w:array[0..65536,0..160]of longint;
u:array[0..65536]of boolean;
ans:array[0..16000]of char;
t:array[0..16000]of longint;
procedure swap(var a,b:longint);
var
t:longint;
begin
t:=a; a:=b; b:=t;
end;
procedure f(s,p:longint);
var len,i:longint;
begin
len:=0;
fillchar(t,sizeof(t),0);
// write(s,'=');
while s>=1 do begin
inc(len);
if s mod 2=0 then t[len]:=0
else t[len]:=1;
s:=s div 2;
end;
for i:=1 to 16 div 2 do
swap(t[i],t[16-i+1]);
for i:=1 to 16 do w[p,i]:=t[i];
end;
begin
readln(a,b,c,s);
fillchar(u,sizeof(u),false);
u[s]:=true;
p:=1;
f(s,p);
while true do begin
s:=(a*s+b) mod c;
if u[s] then break;
u[s]:=true;
inc(p);
f(s,p);
end;
for i:=1 to 16 do begin
cnt:=0;
for j:=1 to p do begin
cnt:=cnt+w[j,i];
end;
inc(kk);
if cnt=0 then ans[kk]:='0'
else if cnt=p then ans[kk]:='1'
else ans[kk]:='?'
end;
for i:=1 to kk do write(ans[i]);
writeln;
close(input);
close(outp