intmain() { int n, m, c; std::cin >> n >> m >> c; poly a(Mod - 1), b(Mod - 1); for (int i = 0, x; i < n; ++ i) scanf("%d", &x), adj(a[(LL) i * i % (Mod - 1)] += x - Mod); for (int i = 0, x; i < m; ++ i) scanf("%d", &x), adj(b[(LL) i * i * i % (Mod - 1)] += x - Mod); for (int i = 0; i < Mod - 1; ++ i) a[i] = (LL) a[i] * qpow(c, Mod - 1 - i * (i - 1LL) / 2 % (Mod - 1)) % Mod; for (int i = 0; i < Mod - 1; ++ i) b[i] = (LL) b[i] * qpow(c, Mod - 1 - i * (i - 1LL) / 2 % (Mod - 1)) % Mod; a = a * b; for (int i = 0, ed = a.size(); i < ed; ++ i) a[i] = (LL) a[i] * qpow(c, i * (i - 1LL) / 2 % (Mod - 1)) % Mod; int res = 0; for (int &x : a) adj(res += x - Mod); std::cout << res << '\n'; return0; }