#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
ll a[22];
ll po[18];
int dig(ll n){
int cnt=0;
while(n){
cnt++;
n/=10;
}
cnt=max(cnt,1);
return cnt;
}
ll np(ll n,int k){
k--;
//cout<<k<<endl;
//int f=k/2;
//cout<<f<<' '<<po[f]<<endl;
ll p=po[k/2]+(n-1);
//cout<<p<<endl;
//printf("%lld",p);
ll sum=p;
if(k%2==0)p/=10;
while(p){
sum*=10;
sum+=p%10;
p/=10;
}
return sum;
}
ll bs(ll n,ll lo,ll hi,int d,bool ck){
int cnt=0;
while(lo<hi){
//cout<<lo<<' '<<hi<<' '<<n<<endl;
//if(cnt==10)break;
cnt++;
ll mid=(lo+hi)/2;
ll val=np(mid,d);
if(val==n){
lo=mid;
break;
}
if(val<n)lo=mid+1;
else hi=mid-1;
}
if(lo<hi){
ll v1=np(hi,d);
if(v1<=n)lo=hi;
}
//cout<<np(lo,d)<<' '<<lo<<endl;
if(!ck && np(lo,d)>n)lo--;
//if(ck && np(lo,d)>n)lo++;
if(ck && np(lo,d)>=n)lo--;
//cout<<np(lo,d)<<' '<<lo<<endl;
return lo;
}
int main(){
po[0]=1;
for(int i=1;i<=17;i++){
po[i]=po[i-1]*10;
}
a[0]=0;
a[1]=10;
a[2]=a[1]+9;
ll ss=9;
for(int i=3;i<=18;i++){
if(i&1)ss*=10;
a[i]=a[i-1]+ss;
}
//for(int i=1;i<=19;i++)cout<<a[i]<<' ';cout<<endl;
int t,c=0;
scanf("%d",&t);
while(t--){
ll x,y;
scanf("%lu%lu",&x,&y);
if(x>y)swap(x,y);
int f1=dig(x);
int f2=dig(y);
ll val=a[f2-1]-a[f1-1];
ll lo=0,hi=a[f2]-a[f2-1];
if(f2>1)val+=bs(y,lo,hi,f2,0);
else val=y+1;
hi=a[f1]-a[f1-1];
if(x>1)val-=bs(x,lo,hi,f1,1);
else val-=x;
printf("Case %d: %lu\n",++c,val);
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiB1bnNpZ25lZCBsb25nIGxvbmcgaW50IGxsOwpsbCBhWzIyXTsKbGwgcG9bMThdOwppbnQgZGlnKGxsIG4pewogICAgaW50IGNudD0wOwogICAgd2hpbGUobil7CiAgICAgICAgY250Kys7CiAgICAgICAgbi89MTA7CiAgICB9CiAgICBjbnQ9bWF4KGNudCwxKTsKICAgIHJldHVybiBjbnQ7Cn0KbGwgbnAobGwgbixpbnQgayl7CiAgICBrLS07CiAgICAvL2NvdXQ8PGs8PGVuZGw7CiAgICAvL2ludCBmPWsvMjsKICAgIC8vY291dDw8Zjw8JyAnPDxwb1tmXTw8ZW5kbDsKICAgIGxsIHA9cG9bay8yXSsobi0xKTsKICAgIC8vY291dDw8cDw8ZW5kbDsKICAgIC8vcHJpbnRmKCIlbGxkIixwKTsKICAgIGxsIHN1bT1wOwogICAgaWYoayUyPT0wKXAvPTEwOwogICAgd2hpbGUocCl7CiAgICAgICAgc3VtKj0xMDsKICAgICAgICBzdW0rPXAlMTA7CiAgICAgICAgcC89MTA7CiAgICB9CiAgICByZXR1cm4gc3VtOwp9CmxsIGJzKGxsIG4sbGwgbG8sbGwgaGksaW50IGQsYm9vbCBjayl7CiAgICBpbnQgY250PTA7CiAgICB3aGlsZShsbzxoaSl7CiAgICAgICAgLy9jb3V0PDxsbzw8JyAnPDxoaTw8JyAnPDxuPDxlbmRsOwogICAgICAgIC8vaWYoY250PT0xMClicmVhazsKICAgICAgICBjbnQrKzsKICAgICAgICBsbCBtaWQ9KGxvK2hpKS8yOwogICAgICAgIGxsIHZhbD1ucChtaWQsZCk7CiAgICAgICAgaWYodmFsPT1uKXsKICAgICAgICAgICAgbG89bWlkOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgaWYodmFsPG4pbG89bWlkKzE7CiAgICAgICAgZWxzZSBoaT1taWQtMTsKICAgIH0KICAgIGlmKGxvPGhpKXsKICAgICAgICBsbCB2MT1ucChoaSxkKTsKICAgICAgICBpZih2MTw9bilsbz1oaTsKICAgIH0KICAgIC8vY291dDw8bnAobG8sZCk8PCcgJzw8bG88PGVuZGw7CiAgICBpZighY2sgJiYgbnAobG8sZCk+bilsby0tOwogICAgLy9pZihjayAmJiBucChsbyxkKT5uKWxvKys7CiAgICBpZihjayAmJiBucChsbyxkKT49bilsby0tOwogICAgLy9jb3V0PDxucChsbyxkKTw8JyAnPDxsbzw8ZW5kbDsKICAgIHJldHVybiBsbzsKfQppbnQgbWFpbigpewogICAgcG9bMF09MTsKICAgIGZvcihpbnQgaT0xO2k8PTE3O2krKyl7CiAgICAgICAgcG9baV09cG9baS0xXSoxMDsKICAgIH0KICAgIGFbMF09MDsKICAgIGFbMV09MTA7CiAgICBhWzJdPWFbMV0rOTsKICAgIGxsIHNzPTk7CiAgICBmb3IoaW50IGk9MztpPD0xODtpKyspewogICAgICAgIGlmKGkmMSlzcyo9MTA7CiAgICAgICAgYVtpXT1hW2ktMV0rc3M7CiAgICB9CiAgICAvL2ZvcihpbnQgaT0xO2k8PTE5O2krKyljb3V0PDxhW2ldPDwnICc7Y291dDw8ZW5kbDsKICAgIGludCB0LGM9MDsKICAgIHNjYW5mKCIlZCIsJnQpOwogCiAgICB3aGlsZSh0LS0pewogICAgICAgIGxsIHgseTsKICAgICAgICBzY2FuZigiJWx1JWx1IiwmeCwmeSk7CiAgICAgICAgaWYoeD55KXN3YXAoeCx5KTsKICAgICAgICBpbnQgZjE9ZGlnKHgpOwogICAgICAgIGludCBmMj1kaWcoeSk7CiAgICAgICAgbGwgdmFsPWFbZjItMV0tYVtmMS0xXTsKICAgICAgICBsbCBsbz0wLGhpPWFbZjJdLWFbZjItMV07CiAgICAgICAgaWYoZjI+MSl2YWwrPWJzKHksbG8saGksZjIsMCk7CiAgICAgICAgZWxzZSB2YWw9eSsxOwogICAgICAgIGhpPWFbZjFdLWFbZjEtMV07CiAgICAgICAgaWYoeD4xKXZhbC09YnMoeCxsbyxoaSxmMSwxKTsKICAgICAgICBlbHNlIHZhbC09eDsKICAgICAgICBwcmludGYoIkNhc2UgJWQ6ICVsdVxuIiwrK2MsdmFsKTsKICAgIH0KIAp9