"""练习 22 进阶版：使用 int 的进制解析和 format 格式化转换。"""
text = input().strip()
source_base, target_base = map(int, input().split())
if source_base not in {2, 8, 10, 16} or target_base not in {2, 8, 10, 16}:
    raise ValueError("进制只能是 2、8、10 或 16")

number = int(text, source_base)
if number < 0:
    raise ValueError("本练习只处理非负整数")

format_codes = {2: "b", 8: "o", 10: "d", 16: "X"}
print(format(number, format_codes[target_base]))
