program cifra;
var t,i:longint;
x,y,z:double;
s,p,j,l:integer;
c:0..10;
k:array[0..1,0..9] of 0..9 = ((0,1,6,3,6,5,6,7,4,9),(0,1,4,7,6,5,6,3,6,9));
f,g:text;
begin
assign(f,'cifra.in');
assign(g,'cifra.out');
reset(f);
rewrite(g);
readln(f,t);
for i:=1 to t do
begin
readln(f,x);
y:=int((x-1)/10);
if y/2 = int(y/2) then
l:=1
else
l:=0;
s:=trunc(frac((y*7)/10)*10);
c:= round(frac(x/10)*10);
if c=0 then c:=10;
for j:=0 to c do
s := (s + k[l,j mod 10]) mod 10;
writeln(g,s);
end;
close(f);
close(g);
end.