program zeroandone;
var
w,one:array[1..100]of int64;
a,b,d1,d2,d:int64;
i,j,q,p:longint;
begin
assign (input,'infinit.in');
reset (input);
assign (output,'infinit.out');
rewrite (output);
readln(q);
w[1]:=1;
w[2]:=2;
one[1]:=1;
one[2]:=1;
for i:=3 to 91 do
begin
w[i]:=w[i-1]+w[i-2];
one[i]:=one[i-1]+one[i-2]
end;
for p:=1 to q do
begin
readln(a,b);
a:=a-1;
d1:=0;
d2:=0;
for i:=91 downto 1 do
begin
if w[i]<=a then
begin
d1:=d1+one[i];
a:=a-w[i]
end
end;
for i:=91 downto 1 do
if w[i]<=b then
begin
d2:=d2+one[i];
b:=b-w[i]
end;
d:=d2-d1;
writeln (d)
end;
close (input);
close (output);
end.