#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
using ll = long long;
int n, m, P, a[N], b[N], q[N];
ll dp[N];
ll qpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % P;
    a = a * a % P;
    b >>= 1;
  }
  return ret;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> P;
  int t = P - 1;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i], t = gcd(b[i], t);
  vector<int> d;
  for (int i = 1; i * i < P; i++)
    if ((P - 1) % i == 0) {
      d.push_back(i);
      if (i * i != P - 1) d.push_back((P - 1) / i);
    }
  sort(d.begin(), d.end());
  for (int i = 1; i <= n; i++) {
    a[i] = qpow(a[i], t);
    for (auto &j : d)
      if (qpow(a[i], j) == 1) {
        q[i] = (P - 1) / j;
        break;
      }
  }
  sort(q + 1, q + n + 1);
  n = unique(q + 1, q + n + 1) - q - 1;
  ll ans = 0;
  for (int i = d.size() - 1; i >= 0; --i) {
    bool fl = 0;
    for (int j = 1; j <= n; j++)
      if (d[i] % q[j] == 0) {
        fl = 1;
        for (int k = i + 1; k < d.size(); k++)
          if (d[k] % d[i] == 0) dp[i] = (dp[i] - dp[k]) % P;
        break;
      }
    if (fl) {
      dp[i] = (dp[i] + (P - 1) / d[i]) % P;
      ans = (ans + dp[i]) % P;
    }
  }
  cout << (ans + P) % P << endl;
  return 0;
}
