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

using namespace std;

string conv(long long x, int base) {
    if (base == 2) {
        if (x == 0) return "0";
        string res = "";
        while (x > 0) {
            res += char('0' + (x % 2));
            x /= 2;
        }
        reverse(res.begin(), res.end());
        return res;
    }

    if (base == 4) {
        if (x == 0) return "0";
        string digs = "0123456789ABCDEF";
        string res = "";
        while (x > 0) {
            res += digs[x % 4];
            x /= 4;
        }
        reverse(res.begin(), res.end());
        return res;
    }

    if (base == 8) {
        if (x == 0) return "0";
        string res = "";
        while (x > 0) {
            res += char('0' + (x % 8));
            x /= 8;
        }
        reverse(res.begin(), res.end());
        return res;
    }

    if (base == 16) {
        if (x == 0) return "0";
        string digs = "0123456789ABCDEF";
        string res = "";
        while (x > 0) {
            res += digs[x % 16];
            x /= 16;
        }
        reverse(res.begin(), res.end());
        return res;
    }

    return "";
}

int main() {
    string a, b;
    int typ1, typ2, typ_out;

    cin >> a >> typ1;
    cin >> b >> typ2;
    cin >> typ_out;

    long long A = stoll(a, nullptr, typ1);
    long long B = stoll(b, nullptr, typ2);

    long long S = A + B;
    long long P = A * B;

    cout << conv(S, typ_out) << endl;
    cout << conv(P, typ_out) << endl;

    return 0;
}