#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

long long toDec(string s, int base) {
    long long x = 0;

   for (int i = 0; i < s.size(); i++) {
    char c = s[i]; 
	        int d;
        if (c >= '0' && c <= '9')
            d = c - '0';
        else
            d = c - 'A' + 10;

        x = x * base + d;
    }

    return x;
}

string convert(long long x, int base) {
    string digits = "0123456789ABCDEF";
    string ans;

    while (x > 0) {
        ans += digits[x % base];
        x /= base;
    }

    reverse(ans.begin(), ans.end());

    return ans;
}

int main() {
    string a, b;
    int c, d, e;

    cin >> a >> c;
    cin >> b >> d;
    cin >> e;

    long long A = toDec(a, c);
    long long B = toDec(b, d);

    cout << convert(A + B, e) << '\n';
    cout << convert(A * B, e) << '\n';

    return 0;
}