var
s,t:string;
x,y:int64;
a,b:array[0..10000]of longint;
i,j,q:longint;
function go(k:int64):int64;
begin
if k=0 then exit(0);
if k<=20 then exit(a[k]);
exit(b[55]*((k-20) div 55)+a[20]+b[(k-20) mod 55]);
end;
begin
assign(input,'infinit.in'); reset(input);
assign(output,'infinit.out'); rewrite(output);
s:='1';
for i:=1 to 20 do
begin
t:='';
for j:=1 to length(s) do
if s[j]='1' then t:=t+'10'
else t:=t+'1';
s:=t;
end;
for i:=1 to 20 do
if s[i]='1' then a[i]:=a[i-1]+1
else a[i]:=a[i-1];
for i:=21 to 75 do
if s[i]='1' then b[i-20]:=b[i-21]+1
else b[i-20]:=b[i-21];
readln(q);
for i:=1 to q do
begin
readln(x,y);
writeln(go(y)-go(x-1));
end;
close(input);
close(output);
end.