#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <cassert>#include <iostream>#include <sstream>#include <fstream>#include <map>#include <set>#include <vector>#include <queue>#include <algorithm>#include <iomanip>using namespace std;int k;char str1[1005],str2[15];__int64 mod,t,tt,ttt;int ans[15],num;int main(){ while(scanf("%d",&k)!=EOF&&k!=0) { scanf("%s",str1); scanf("%s",str2); mod=0; t=1; for(int i=strlen(str2)-1; i>=0; i--) { mod=mod+(str2[i]-48)*t; t=t*k; } tt=0; t=1; for(int i=strlen(str1)-1; i>=0; i--) { tt=(tt+(str1[i]-48)*t)%mod; t=(t*k)%mod; } ttt=tt; num=0; while(ttt) { ans[++num]=ttt%k; ttt=ttt/k; } if(num==0||tt==0) printf("0n"); else { for(int i=num; i>=1; i--) printf("%d",ans[i]); printf("n"); } } return 0;}