#include
#include
typedef struct sn
{
int data;
struct sn *next;
} sn, *ls;
void creat(ls s)
{
s = NULL;
}
sn *input(ls s, int n, int m)
{
int a, b;
a = n;
ls p ;p=s;
while (a != 0)
{
// a=a/m;c=a;//printf("%d",-m*a+c);
b = a % m;
a = a / m; // printf("%d\n",b);
p = (sn*) malloc(sizeof(sn));
p->data = b;
p->next = s;
s = p;
}return s;
}
void output(ls s)
{
ls p = s;
while (s!=NULL)
{
printf("%d\n", s->data);
p = s;
s = s->next;
free(p);
}
}
//printf("aaaaaaaaaa\n");
int main()
{
int n, m;
char p;
while (scanf("%d %c %d", &n, &p, &m) != EOF)
{
// printf("%d %d\n",n,m);
ls s;
creat(s);
s=input(s, n, m);
output(s);
printf("\n");
}
return 0;
}