//Java版代码
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int n = Integer.parseInt(scanner.next(), a);
        int b = scanner.nextInt();
        System.out.println(Integer.toString(n, b).toUpperCase());
    }
}
#Python版代码
a, n, b = input().split()
a = int(a)
n = int(n, a)
b = int(b)  
ans = []
while n:
    temp = n % b
    if temp >= 10:
        ans.append(chr(temp % 10 + ord("A")))
    else:
        ans.append(chr(temp + ord("0")))
    n //= b
print("".join(ans[::-1]))