#include <cstdio>
using namespace std;
typedef long long ll;
ll calc(ll a,ll b){return b==0?1:a/b+calc(b,a%b);}
int main()
{
    int T,t=0;
    scanf("%d",&T);
    while(T--)
    {
        ll a,b,ans;
        scanf("%lld%lld",&a,&b);
        if((a|b)==0) ans=1;
        else if((a&&b)==0) ans=2;
        else ans=calc(a,b);
        printf("Case #%d: %lld\n",++t,ans);
    }
    return 0;
}
