var
f:array[1..2000000]of integer;
a,b,c,d,n,g,t:longint;
begin
assign(input,'number1.in');
assign(output,'number1.out');
reset(input);
rewrite(output);
while not eof do
begin
read(a,b,n);
if n<=2 then writeln('1');
if n>=3 then
begin
f[1]:=1;
f[2]:=1;
t:=0;
for c:=3 to n do
begin
f[c]:=(a*f[c-1]+b*f[c-2]) mod 7;
for d:=2 to c-2 do
if (f[c-1]=f[d-1])and(f[c]=f[d]) then
begin
t:=1;
break;
end;
if t=1 then break;
end;
if c=n then writeln(f[n]) else
if (n-d+2)mod(c-d)=0 then writeln(f[c-2]) else writeln(f[d-2+(n-d+2) mod (c-d)]);
end;
end;
close(input);close(output);
end.