def fun(a):
    if a < 10:
        return str(a)
    elif a >= 10:
        return chr(65 + a - 10)
    

def tentoany(a, b):
    res = ''
    while a:
        res = fun(a%b) + res
        a = a // b
    return res

while True:
    try:
        s = input().split()
        n = int(s[1], int(s[0]))
       
        res = tentoany(n, int(s[2]))
        print(res)
    except:
        break