#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,sum;
cin>>a;
for(int i=1;i<=a;i++)
{
cin>>b>>c;
sum=0;
while(1)
{
if(b==sqrt(b)*sqrt(b))
{
b=sqrt(b);
break;
}
b--;
}
while(1)
{
if(c==sqrt(c)*sqrt(c))
{
c=sqrt(c);
break;
}
c--;
}
if(b==1) sum=(c*(c+1)*(2*c+1))/6;
else sum=(c*(c+1)*(2*c+1))/6-(b*(b+1)*(2*b+1))/6;
cout<<"Case "<<i<<": "<<sum<<endl;
}
}