Pagini recente » Cod sursa (job #917457) | Cod sursa (job #3199368) | Cod sursa (job #1692711) | Cod sursa (job #1102730) | Cod sursa (job #1147357)
var a: array[1..1000] of byte;
u: array[1..1000] of boolean;
t,i, j, k, c, n: integer;
s: string;
begin
assign(input,'cifra.in');
reset(input);
assign(output,'cifra.out');
rewrite(output);
for i:=1 to 1000 do u[i]:=false;
i:=5;
while i<=1000
do Begin
a[i]:=5; u[i]:=true;
i:=i+10;
end;
i:=6;
while i<=1000
do Begin
a[i]:=6; u[i]:=true;
i:=i+10;
end;
i:=10;
while i<=1000
do Begin
a[i]:=0; u[i]:=true;
i:=i+10;
end;
i:=1;
while i<=1000
do Begin
a[i]:=1; u[i]:=true;
i:=i+10;
end;
i:=-8;
while i<1000 do begin
i:=i+10; c:=i; j:=0;
while i<=1000 do
Begin
inc(j); u[i]:=true;
case (i*j mod 4) of
0 : a[i]:=6;
1 : a[i]:=2;
2 : a[i]:=4;
3 : a[i]:=8;
end;
i:=i*2;
end; i:=c; end;
i:=-7;
while i<1000 do begin
i:=i+10; c:=i; j:=0;
while i<=1000 do
Begin
inc(j); u[i]:=true;
case (i*j mod 4) of
0 : a[i]:=1;
1 : a[i]:=3;
2 : a[i]:=9;
3 : a[i]:=7;
end;
i:=i*3;
end; i:=c; end;
i:=-3;
while i<1000 do Begin
i:=i+10; c:=i; j:=0;
while i<=1000 do
Begin
inc(j); u[i]:=true;
case (i*j mod 4) of
0 : a[i]:=1;
1 : a[i]:=7;
2 : a[i]:=9;
3 : a[i]:=3;
end;
i:=i*7;
end; i:=c; end;
i:=-1;
while i<1000 do Begin
i:=i+10; c:=i; j:=0;
while i<=1000 do
Begin
inc(j); u[i]:=true;
case (i*j mod 2) of
0 : a[i]:=1;
1 : a[i]:=9;
end;
i:=i*9;
end; i:=c; end;
i:=-6;
while i<1000 do Begin
i:=i+10; c:=i; j:=0;
while i<=1000 do
Begin
inc(j); u[i]:=true;
case (i*j mod 2) of
0 : a[i]:=6;
1 : a[i]:=4;
end;
i:=i*4;
end; i:=c; end;
i:=-2;
while i<1000 do Begin
i:=i+10; c:=i; j:=0;
while i<=1000 do
Begin
inc(j); u[i]:=true;
case (i*j mod 4) of
0 : a[i]:=6;
1 : a[i]:=8;
2 : a[i]:=4;
3 : a[i]:=2;
end;
i:=i*8;
end; i:=c; end;
for i:=2 to 20 do
a[i]:=(a[i]+a[i-1]) mod 10;
{
for i:=1 to 250 do
begin write(a[i],' ');
if i mod 20=0 then writeln ; end;
}
readln(t);
for i:=1 to t do
begin
readln(s);
if length(s)=1 then writeln(a[ord(s[1])-48])
else
writeln(a[ord(s[length(s)-1])*10+ord(s[length(s)]) mod 20]);
end;
close(output);
close(input);
end.