#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
const int dx[] = {0, 0, 1, -1, 1, -1, 1, -1},
          dy[] = {-1, 1, 0, 0, 1, -1, -1, 1};
void run();
int main() {
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(16);
  run();
}
const int maxn = 100100;
ll p;
int n, m;
ll a[maxn], b[maxn];
int ai[maxn], bi[maxn];
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<ll> factor(ll x) {
  vector<ll> res;
  for (ll i = 2; i * i <= x; ++i) {
    if (x % i == 0) {
      res.push_back(i);
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) res.push_back(x);
  return res;
}
vector<ll> factors_p1;
ll powmod(ll x, ll e) {
  if (e == 0) return 1;
  if (e & 1) return x * powmod(x, e - 1) % p;
  ll y = powmod(x, e / 2);
  return y * y % p;
}
bool is_primitive(ll g) {
  for (auto q : factors_p1) {
    if (1 == powmod(g, (p - 1) / q)) return 0;
  }
  return 1;
}
ll g;
void find_prim() {
  for (;;) {
    g = (((ll)rand() << 15) | (ll)rand()) % p;
    if (g < 2) continue;
    if (is_primitive(g)) return;
  }
}
unordered_map<ll, ll> powers;
ll dlog(ll b) {
  ll m = (ll)(ceil(sqrt(p - 1)) + 0.5);
  for (int j = (0); j < (m); ++j) powers[powmod(g, j)] = j;
  ll gm = powmod(g, -m + 2 * (p - 1));
  for (int i = (0); i < (m); ++i) {
    if ((powers).find(b) != end(powers)) return i * m + powers[b];
    b = b * gm % p;
  }
  assert(0);
  return -1;
}
ll x[maxn];
int xn;
ll ans;
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
void incex(int i, ll m, int cnt) {
  if (m > p - 1) return;
  if (i == xn) {
    if (cnt == 0) return;
    int f = (cnt % 2) ? 1 : -1;
    ans += f * ((p - 1) / m);
    return;
  }
  incex(i + 1, lcm(m, x[i]), cnt + 1);
  incex(i + 1, m, cnt);
}
vector<ll> divs;
ll findq(ll a, ll k) {
  for (auto x : divs) {
    if (powmod(a, k * x) == 1) return (p - 1) / x;
  }
  assert(0);
  return -1;
}
int d[maxn];
void run() {
  cin >> n >> m >> p;
  for (ll i = 1; i * i <= p - 1; ++i) {
    if ((p - 1) % i == 0) {
      divs.push_back(i);
      if (i * i != p - 1) divs.push_back((p - 1) / i);
    }
  }
  sort(begin(divs), end(divs));
  for (int i = (0); i < (n); ++i) cin >> a[i];
  for (int i = (0); i < (m); ++i) cin >> b[i];
  ll k = p - 1;
  for (int i = (0); i < (m); ++i) k = gcd(k, b[i]);
  for (int i = (0); i < (n); ++i) x[i] = findq(a[i], k);
  sort(x, x + n);
  xn = unique(x, x + n) - x;
  for (int i = xn - 1; i >= 0; --i) {
    bool mult = 0;
    for (int j = 0; j < i; ++j) {
      if (x[i] % x[j] == 0) mult = 1;
    }
    if (mult) {
      for (int j = i; j < xn - 1; ++j) x[j] = x[j + 1];
      xn--;
    }
  }
  if (xn > 10) assert(0);
  ans = 0;
  incex(0, 1, 0);
  cout << ans << endl;
}
