#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T& x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chkmin(T& x, T y) {
  if (x > y) x = y;
}
inline int read() {
  int x = 0;
  char c = getchar();
  bool f = 0;
  while (c < 48) f |= c == '-', c = getchar();
  while (c > 47) x = x * 10 + (c ^ 48), c = getchar();
  return f ? -x : x;
}
const int maxn = 5e4 + 10;
long long K;
int P;
int n, m, S[maxn];
inline void Add(int& x, int y) {
  x += y;
  if (x >= P) x -= P;
}
struct matrix {
  int arr[2][2];
  void clear() { memset(arr, 0, sizeof arr); }
  inline int* operator[](const int& pos) { return arr[pos]; }
  inline void print() {
    for (int i = (0), iend = (1); i <= iend; ++i)
      for (int j = (0), jend = (1); j <= jend; ++j)
        printf("%d%c", arr[i][j], "\n "[j < 1]);
  }
} E;
matrix operator*(matrix A, matrix B) {
  matrix res;
  res.clear();
  for (int k = (0), kend = (1); k <= kend; ++k)
    for (int i = (0), iend = (1); i <= iend; ++i)
      for (int j = (0), jend = (1); j <= jend; ++j)
        Add(res[i][j], 1ll * A[i][k] * B[k][j] % P);
  return res;
}
matrix qp(matrix A, long long k) {
  matrix res = E;
  for (; k; k >>= 1, A = A * A)
    if (k & 1) res = res * A;
  return res;
}
void minit() {
  E.clear();
  for (int i = (0), iend = (1); i <= iend; ++i) E[i][i] = 1;
}
matrix val[maxn << 2];
void build(int k, int l, int r) {
  if (l == r) {
    auto tmp = val[k].arr;
    tmp[0][0] = S[l], tmp[1][0] = S[(l + n - 1) % n], tmp[0][1] = 1,
    tmp[1][1] = 0;
    return;
  }
  build(k << 1, l, ((l + r) >> 1)), build(k << 1 | 1, ((l + r) >> 1) + 1, r),
      val[k] = val[k << 1] * val[k << 1 | 1];
}
matrix query(int k, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return val[k];
  if (qr <= ((l + r) >> 1)) return query(k << 1, l, ((l + r) >> 1), ql, qr);
  if (ql > ((l + r) >> 1))
    return query(k << 1 | 1, ((l + r) >> 1) + 1, r, ql, qr);
  return query(k << 1, l, ((l + r) >> 1), ql, qr) *
         query(k << 1 | 1, ((l + r) >> 1) + 1, r, ql, qr);
}
struct node {
  long long p;
  int s;
} dat[maxn];
matrix trans(long long l, long long r) {
  if (l > r) return E;
  if (l / n == r / n) {
    return query(1, 0, n - 1, l % n, r % n);
  }
  return query(1, 0, n - 1, l % n, n - 1) * qp(val[1], r / n - l / n - 1) *
         query(1, 0, n - 1, 0, r % n);
}
void solve() {
  minit();
  cin >> K >> P >> n;
  if (K < 2) return cout << K % P << endl, void();
  for (int i = (0), iend = (n - 1); i <= iend; ++i) S[i] = read() % P;
  build(1, 0, n - 1);
  cin >> m;
  for (int i = (1), iend = (m); i <= iend; ++i) {
    cin >> dat[i].p;
    dat[i].s = read() % P;
  }
  sort(dat + 1, dat + m + 1, [](node X, node Y) { return X.p < Y.p; });
  long long cur = 1;
  matrix M;
  M.clear(), M.arr[0][0] = 1 % P;
  for (int i = (1), iend = (m); i <= iend; ++i) {
    long long p = dat[i].p;
    if (p >= K) break;
    M = M * trans(cur, p - 1);
    matrix J;
    J[0][0] = dat[i].s, J[0][1] = 1, J[1][1] = 0,
    J[1][0] =
        i > 1 && dat[i - 1].p == dat[i].p - 1 ? dat[i - 1].s : S[(p - 1) % n];
    M = M * J;
    cur = p + 1;
    if (cur == K) break;
    if (i < m && dat[i + 1].p == dat[i].p + 1) continue;
    J[0][0] = S[(p + 1) % n], J[1][0] = dat[i].s;
    M = M * J;
    cur++;
  }
  M = M * trans(cur, K - 1);
  cout << M.arr[0][0] << endl;
}
signed main() {
  solve();
  return 0;
}
