#include <stdio.h>

int gcd(int x,int y)
{
    int r;
    while(y!= 0)
    {
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}
int order(int g,int mod)
{//The minimum n such that g^n == 1(mod mod)
    int multi=1;
    if(mod == 1)
        return 0;
    for(int i=0;i<mod;i++)
    {
        multi*=g;
        multi %= mod;
        if(multi == 1)
            return i+1;
    }
    return -1;
}
int main(void)
{
    int x,y;
    while(scanf("%d%d",&x,&y),x!=0 || y!= 0)
    {
        int g=gcd(x,y);
        x/=g;
        y/=g;
        int cnt=0;
        while(1)
        {
            int f25=gcd(y,10);
            if(f25 == 1)
                break;
            y/=f25;
            cnt++;
        }
        printf("%d %d\n",cnt,order(10,y));
    }
    return 0;
}