#include <iostream>
using namespace std;
int main(){long p,q;while(cin>>p>>q){int j,i=0,c=0,pr[80];pr[0]=p;while(p*=10,c++==i&&p){cout<<(char)(p/q+'0');for(i=0;i<c;i++)if(p%q==pr[i]){cout<<endl;for(j=0;j<c;j++)cout<<(j<i?' ':'^');break;}pr[c]=p%=q;}if(c==1)cout<<'0';cout<<endl;}}