
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define REP(i, n) REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n) for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n) std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n) std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2) ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A) (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2) (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2) (((p1)>(p2))?(p1):(p2))
#define GETSTR(p)           do{ fgets((p), sizeof(p), stdin); } while(0)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n') *_q = 0;      } while(0)
#define GETI1(buf,p1)       do{ GETSTR(buf); sscanf((buf), "%d", &(p1));                    } while(0)
#define GETI2(buf,p1,p2)    do{ GETSTR(buf); sscanf((buf), "%d%d ", &(p1),&(p2));           } while(0)
#define GETI3(buf,p1,p2,p3) do{ GETSTR(buf); sscanf((buf), "%d%d%d ", &(p1),&(p2),&(p3));   } while(0)

#ifdef _DEBUG
#define pf printf
#else
#define pf(...) /* */
#endif

typedef long long ll;
typedef unsigned long long ull;

map <int, int> h;

int main(void){
    int result;
    char buf[1024];

    while(fgets((buf), sizeof(buf), stdin)){
        int p,q;
        sscanf((buf), "%d%d ", &p,&q);
        pf("DEBUG1: %d,%d\n", p,q);

        h.clear();
        h.insert(make_pair(p,0));
        p *= 10;

        int i = 0;
        while(p != 0){
            int d,m;
            d = p/q;
            m = p%q;
            printf("%d", d);
            if(h.find(m) != h.end()) break;

            i++;
            h.insert(make_pair(m, i));
            p = m * 10;
        }
        printf("\n");
        if(p != 0){
            int m = p%q;
            int k = h[m];
            pf("DEBUG2: %d %d\n", i, h[m]);
            REP(j, i+1){
                if(j < k){
                    printf(" ");
                } else {
                    printf("^");
                }
            }
            printf("\n");
        }

    }

    return 0;
}