#include /** * @attention 使用前にstatic変数Mを設定する。 */ class RuntimeModInt{ public: static std::uint32_t M; std::uint64_t val; RuntimeModInt(): val(0){} RuntimeModInt(std::int64_t n){ if(n >= M) val = n % M; else if(n < 0) val = n % M + M; else val = n; } const auto operator+(const RuntimeModInt &a) const {return RuntimeModInt(val + a.val);} const auto operator-(const RuntimeModInt &a) const {return RuntimeModInt(val - a.val);} const auto operator*(const RuntimeModInt &a) const {return RuntimeModInt(val * a.val);} const auto operator/(const RuntimeModInt &a) const {return RuntimeModInt(val * a.inv().val);} const auto& operator=(const RuntimeModInt &a){val = a.val; return *this;} const auto& operator+=(const RuntimeModInt &a){if((val += a.val) >= M) val -= M; return *this;} const auto& operator-=(const RuntimeModInt &a){if(val < a.val) val += M; val -= a.val; return *this;} const auto& operator*=(const RuntimeModInt &a){(val *= a.val) %= M; return *this;} const auto& operator/=(const RuntimeModInt &a){(val *= a.inv().val) %= M; return *this;} const bool operator==(const RuntimeModInt &a) const {return val == a.val;} const bool operator!=(const RuntimeModInt &a) const {return val != a.val;} const static auto power(std::int64_t n, std::int64_t p){ RuntimeModInt ret = 1, e = n; for(; p; e *= e, p >>= 1) if(p & 1) ret *= e; return ret; } const auto power(std::int64_t p) const { RuntimeModInt ret = 1, e = val; for(; p; e *= e, p >>= 1) if(p & 1) ret *= e; return ret; } const RuntimeModInt inv() const { std::int64_t a = val, b = M, u = 1, v = 0; while(b){ std::int64_t t = a/b; a -= t*b; std::swap(a,b); u -= t*v; std::swap(u,v); } u %= M; if(u < 0) u += M; return u; } }; auto operator-(const RuntimeModInt &a){return RuntimeModInt(-a.val);} auto operator+(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(a) + b;} auto operator-(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(a) - b;} auto operator*(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(a) * b;} auto operator/(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(a) / b;} std::uint32_t RuntimeModInt::M; std::istream& operator>>(std::istream &is, RuntimeModInt &a){is >> a.val; return is;} std::ostream& operator<<(std::ostream &os, const RuntimeModInt &a){os << a.val; return os;} using mint = RuntimeModInt; int main(){ int N, M, K; std::cin >> N >> M >> K; mint::M = K; char op; std::cin >> op; std::vector A(N), B(M); for(int i = 0; i < M; ++i) std::cin >> B[i]; for(int i = 0; i < N; ++i) std::cin >> A[i]; mint ans = 0; if(op == '+'){ for(int i = 0; i < N; ++i) ans += A[i] * M; for(int i = 0; i < M; ++i) ans += B[i] * N; }else{ mint sb = std::accumulate(B.begin(), B.end(), 0LL); for(int i = 0; i < N; ++i) ans += A[i] * sb; } std::cout << ans << std::endl; return 0; }