#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX = 10010;
int main()
{
int N,n,m,a,b;
while(cin>>N)
{
while(N--)
{int flag = 0;
int k = 1;
while(cin>>n>>m)
{
if(n == 0&&m == 0) {flag = 1; break;}
int num = 0;
for(a=1;a<n;a++)
for(b=1;b<a;b++)
if((a*a + b*b + m)%(a*b)==0) num++;
printf("Case %d: %d\n",k++,num);
}
if(N>0) cout<<endl;
if(flag == 1) continue;
}
}
return 0;
}
直接水过去,没什么好说