Problem: You are given two arrays a_0, a_1, …, a_{n - 1} and b_0, b_1, …, b_{m-1}, and an integer c.

Compute the following sum:

$$$∑_{i=0}^{n-1} ∑_{j=0}^{m-1} a_i b_j c^{i^2\,j^3}$$$

Since it's value can be really large, print it modulo 490019.

Input

First line contains three integers n, m and c (1 ≤ n, m ≤ 100 000, 1 ≤ c < 490019).

Next line contains exactly n integers a_i and defines the array a (0 ≤ a_i ≤ 1000).

Last line contains exactly m integers b_i and defines the array b (0 ≤ b_i ≤ 1000).

Output

Print one integer — value of the sum modulo 490019.

Examples

Input

2 2 3
0 1
0 1


Output

3


Input

3 4 1
1 1 1
1 1 1 1


Output

12


Input

2 3 3
1 2
3 4 5


Output

65652

Note

In the first example, the only non-zero summand corresponds to i = 1, j = 1 and is equal to 1 ⋅ 1 ⋅ 3^1 = 3.

In the second example, all summands are equal to 1.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
void solve(std::istream &in, std::ostream &out);
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  solve(std::cin, std::cout);
  return 0;
}
const int md = 490019;
int add(int x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
  return x;
}
int mul(int x, int y) { return (long long)x * y % md; }
namespace fft {
const double pi = acos(-1);
struct complex_t {
  double x, y;
  complex_t(double x = 0, double y = 0) : x(x), y(y) {}
  complex_t operator+(const complex_t &b) const {
    return complex_t(x + b.x, y + b.y);
  }
  complex_t operator-(const complex_t &b) const {
    return complex_t(x - b.x, y - b.y);
  }
  complex_t operator*(const complex_t &b) const {
    return complex_t(x * b.x - y * b.y, x * b.y + y * b.x);
  }
};
complex_t conj(complex_t a) { return complex_t(a.x, -a.y); }
vector<complex_t> fa, fb, roots = {complex_t(0, 0), complex_t(1, 0)};
vector<int> rev = {0, 1};
int base = 1;
void ensure_base(int nbase) {
  if (nbase <= base) {
    return;
  }
  rev.resize(1 << nbase);
  for (int i = 0; i < (1 << nbase); ++i) {
    rev[i] = rev[i >> 1] >> 1 | ((i & 1) << nbase - 1);
  }
  roots.resize(1 << nbase);
  while (base < nbase) {
    double angle = 2 * pi / (1 << base + 1);
    for (int i = 1 << base - 1; i < 1 << base; ++i) {
      roots[i << 1] = roots[i];
      double angle_i = angle * ((i << 1) + 1 - (1 << base));
      roots[i << 1 | 1] = complex_t(cos(angle_i), sin(angle_i));
    }
    ++base;
  }
}
void dft(vector<complex_t> &a, int n) {
  int zeros = __builtin_ctz(n);
  ensure_base(zeros);
  int shift = base - zeros;
  for (int i = 0; i < n; ++i) {
    if (i < rev[i] >> shift) {
      swap(a[i], a[rev[i] >> shift]);
    }
  }
  for (int i = 1; i < n; i <<= 1) {
    for (int j = 0; j < n; j += i << 1) {
      for (int k = 0; k < i; ++k) {
        complex_t x = a[j + k], y = a[j + k + i] * roots[i + k];
        a[j + k] = x + y;
        a[j + k + i] = x - y;
      }
    }
  }
}
vector<int> pmul(vector<int> &a, vector<int> &b) {
  int need = a.size() + b.size() - 1, nbase = 0;
  while (1 << nbase < need) {
    ++nbase;
  }
  ensure_base(nbase);
  int size = 1 << nbase;
  if (size > fa.size()) {
    fa.resize(size);
  }
  if (size > fb.size()) {
    fb.resize(size);
  }
  for (int i = 0; i < a.size(); i++) {
    int x = (a[i] % md + md) % md;
    fa[i] = complex_t(x & (1 << 15) - 1, x >> 15);
  }
  for (int i = a.size(); i < size; ++i) {
    fa[i] = complex_t(0, 0);
  }
  dft(fa, size);
  for (int i = 0; i < b.size(); ++i) {
    int x = (b[i] % md + md) % md;
    fb[i] = complex_t(x & (1 << 15) - 1, x >> 15);
  }
  for (int i = b.size(); i < size; ++i) {
    fb[i] = complex_t(0, 0);
  }
  dft(fb, size);
  double ratio = 0.25 / size;
  complex_t r1(1, 0);
  complex_t r2(0, -1);
  complex_t r3(ratio, 0);
  complex_t r4(0, -ratio);
  complex_t r5(0, 1);
  for (int i = 0; i <= size >> 1; ++i) {
    int j = size - i & size - 1;
    complex_t a1 = (fa[i] + conj(fa[j])) * r1;
    complex_t a2 = (fa[i] - conj(fa[j])) * r2;
    complex_t b1 = (fb[i] + conj(fb[j])) * r3;
    complex_t b2 = (fb[i] - conj(fb[j])) * r4;
    if (i != j) {
      complex_t c1 = (fa[j] + conj(fa[i])) * r1;
      complex_t c2 = (fa[j] - conj(fa[i])) * r2;
      complex_t d1 = (fb[j] + conj(fb[i])) * r3;
      complex_t d2 = (fb[j] - conj(fb[i])) * r4;
      fa[i] = c1 * d1 + c2 * d2 * r5;
      fb[i] = c1 * d2 + c2 * d1;
    }
    fa[j] = a1 * b1 + a2 * b2 * r5;
    fb[j] = a1 * b2 + a2 * b1;
  }
  dft(fa, size);
  dft(fb, size);
  vector<int> c(need);
  for (int i = 0; i < need; i++) {
    long long aa = fa[i].x + 0.5;
    long long bb = fb[i].x + 0.5;
    long long cc = fa[i].y + 0.5;
    c[i] = (aa + (bb % md << 15) + (cc % md << 30)) % md;
  }
  return c;
}
}  // namespace fft
using fft::pmul;
constexpr int P = 490019;
void solve(std::istream &in, std::ostream &out) {
  int n, m, c;
  in >> n >> m >> c;
  vector<int> a(P - 1), b(P - 1), inv(P);
  inv[1] = 1;
  for (int i = 2; i < P; ++i)
    inv[i] = (P - (int64_t)inv[P % i] * (P / i) % P) % P;
  for (int i = 0, x; i < n; ++i) {
    in >> x;
    (a[(int64_t)i * i % (P - 1)] += x) %= P;
  }
  for (int i = 0, x; i < m; ++i) {
    in >> x;
    (b[(int64_t)i * i * i % (P - 1)] += x) %= P;
  }
  vector<int> powc(P - 1, 1);
  for (int i = 1; i < P - 1; ++i) powc[i] = (int64_t)powc[i - 1] * c % P;
  int comb = 0;
  for (int i = 0; i < P - 1; ++i) {
    if (i > 0) comb = (comb + P + i - 1) % (P - 1);
    a[i] = ((int64_t)a[i] * inv[powc[comb]]) % P;
    b[i] = ((int64_t)b[i] * inv[powc[comb]]) % P;
  }
  vector<int> conv = pmul(a, b);
  int res = 0;
  comb = 0;
  for (int i = 0; i < (int)conv.size(); ++i) {
    if (i > 0) comb = (comb + P + i - 1) % (P - 1);
    (res += (int64_t)conv[i] * powc[comb] % P) %= P;
  }
  out << res << '\n';
}