#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
using namespace std;
long long K, P;
long long n, s[101000], pos[101000];
long long m;
pair<long long, long long> ss[101000], fx[101000];
long long ftot;
struct matrix {
  long long n;
  long long h[2][2];
  matrix() {
    n = 0;
    h[0][0] = h[0][1] = h[1][0] = h[1][1] = 0;
  }
  matrix(long long nn) {
    n = nn;
    h[0][0] = h[0][1] = h[1][0] = h[1][1] = 0;
  }
  matrix(long long x, long long y) {
    n = 1;
    h[0][0] = x;
    h[0][1] = y;
    h[1][0] = h[1][1] = 0;
  }
  matrix(long long t, long long x, long long y) {
    n = 2;
    h[0][0] = 0, h[0][1] = x, h[1][0] = 1, h[1][1] = y;
  }
  inline matrix operator*(const matrix &a) const {
    matrix mt(n);
    for (long long k = 0; k < 2; ++k) {
      for (long long i = 0; i < 2; ++i) {
        for (long long j = 0; j < 2; ++j) {
          mt.h[i][j] = (mt.h[i][j] + h[i][k] * a.h[k][j]) % P;
        }
      }
    }
    return mt;
  }
} nw, val[201000];
long long ls[201000], rs[201000], ttot, root;
void build(long long L, long long R, long long &cur) {
  cur = ++ttot;
  if (L == R)
    return val[cur] = matrix(1, L ? s[L - 1] : s[n - 1], s[L]), void();
  long long mid = (L + R) >> 1;
  build(L, mid, ls[cur]), build(mid + 1, R, rs[cur]);
  val[cur] = val[ls[cur]] * val[rs[cur]];
}
matrix query(long long L, long long R, long long l, long long r,
             long long cur) {
  if (l <= L && R <= r) return val[cur];
  long long mid = (L + R) >> 1;
  if (l <= mid && r > mid)
    return query(L, mid, l, r, ls[cur]) * query(mid + 1, R, l, r, rs[cur]);
  if (l <= mid) return query(L, mid, l, r, ls[cur]);
  return query(mid + 1, R, l, r, rs[cur]);
}
inline void Pow(matrix &res, matrix x, long long k) {
  while (k) {
    if (k & 1) res = res * x;
    x = x * x;
    k >>= 1;
  }
}
inline long long get_block(long long p) { return p / n; }
inline long long get_end(long long p) { return n * get_block(p) + n - 1; }
long long ptr;
inline void To(long long p) {
  if (ptr == p) return;
  if (p <= get_end(ptr))
    return nw = nw * query(0, n - 1, (ptr + 1) % n, p % n, root), ptr = p,
           void();
  if (ptr % n != n - 1)
    nw = nw * query(0, n - 1, (ptr + 1) % n, n - 1, root), ptr = get_end(ptr);
  Pow(nw, val[root], get_block(p) - get_block(ptr) - 1);
  nw = nw * query(0, n - 1, 0, p % n, root);
  ptr = p;
}
signed main() {
  read(K), read(P);
  if (K == 0) {
    puts("0");
    return 0;
  }
  if (K == 1) {
    printf("%lld\n", 1 % P);
    return 0;
  }
  read(n);
  for (long long i = 0; i < n; ++i) read(s[i]);
  s[n] = s[0];
  read(m);
  for (long long i = 1; i <= m; ++i) {
    read(ss[i].first), read(ss[i].second);
  }
  sort(ss + 1, ss + m + 1);
  ss[m + 1] = ss[0] = make_pair(-242352423425ll, -124324532523ll);
  for (long long i = 1; i <= m && ss[i].first < K; ++i) {
    if (ss[i].first == ss[i - 1].first + 1) {
      fx[++ftot] = make_pair(ss[i - 1].second, ss[i].second);
      pos[ftot] = ss[i].first;
    } else {
      fx[++ftot] = make_pair(s[(ss[i].first - 1) % n], ss[i].second);
      pos[ftot] = ss[i].first;
    }
    if (ss[i].first == ss[i + 1].first - 1) {
      continue;
    } else {
      fx[++ftot] = make_pair(ss[i].second, s[(ss[i].first + 1) % n]);
      pos[ftot] = ss[i].first + 1;
    }
  }
  build(0, n - 1, root);
  ptr = 0;
  nw = matrix(0, 1);
  for (long long i = 1; i <= ftot; ++i) {
    long long p = pos[i];
    if (p >= K) break;
    To(p - 1);
    nw = nw * matrix(1, fx[i].first, fx[i].second);
    ptr++;
  }
  To(K - 1);
  printf("%lld\n", (nw.h[0][1] % P + P) % P);
  return 0;
}
