1 type
2 arr=array [1..2,1..2] of longint;
3 var
4 n,t,ans,nm:longint;
5 a,c:arr;
6 procedure mi(a,b:arr);
7 var
8 i,j,k:longint;
9 begin
10 fillchar(c,sizeof(c),0);
11 for i:=1 to 2 do
12 for j:=1 to 2 do
13 for k:=1 to 2 do
14 c[i,k]:=(c[i,k]+a[i,j]*b[j,k]) mod 1000;
15 end;
16
17 procedure main(n:longint);
18 begin
19 if n<=1 then exit;
20 main(n div 2);
21 mi(c,c);
22 if n mod 2=1 then mi(c,a);
23 end;
24
25 begin
26 assign(input,'Count.in');
27 assign(output,'Count.out');
28 reset(input);
29 rewrite(output);
30 readln(t); nm:=0;
31 while t>0 do
32 begin
33 inc(nm);
34 readln(n);
35 a[1,1]:=0; a[1,2]:=-4;
36 a[2,1]:=1; a[2,2]:=6;
37 c:=a;
38 main(n);
39 ans:=(c[1,1]+c[2,2]+1999) mod 1000;
40 write('Case #',nm,': ');
41 if ans<10 then write('00') else
42 if ans<100 then write('0');
43 writeln(ans);
44 dec(t);
45 end;
46 close(input);
47 close(output);
48 end.