#include <bits/stdc++.h>
using namespace std;
const int N = 114514;
long long k;
int md, n, s[N], m;
struct qwq {
  long long x;
  int v;
  inline bool operator<(const qwq& rhs) const { return x < rhs.x; }
} B[N];
struct mat {
  int A[2][2];
  inline int* operator[](const int& x) { return A[x]; }
  inline mat() { A[0][0] = A[0][1] = A[1][0] = A[1][1] = 0; }
  inline mat(const int& a, const int& b, const int& c, const int& d) {
    A[0][0] = a, A[0][1] = b, A[1][0] = c, A[1][1] = d;
  }
  inline mat operator*(const mat& b) const {
    mat c;
    c[0][0] =
        ((long long)A[0][0] * b.A[0][0] + (long long)A[0][1] * b.A[1][0]) % md;
    c[0][1] =
        ((long long)A[0][0] * b.A[0][1] + (long long)A[0][1] * b.A[1][1]) % md;
    c[1][0] =
        ((long long)A[1][0] * b.A[0][0] + (long long)A[1][1] * b.A[1][0]) % md;
    c[1][1] =
        ((long long)A[1][0] * b.A[0][1] + (long long)A[1][1] * b.A[1][1]) % md;
    return c;
  }
} d[N << 2], f;
vector<pair<long long, mat> > vec;
void build(int l, int r, int o) {
  if (l == r)
    d[o] = mat(0, s[l - 1], 1, s[l]);
  else {
    const int mid = l + r >> 1;
    build(l, mid, o << 1), build(mid + 1, r, o << 1 | 1);
    d[o] = d[o << 1] * d[o << 1 | 1];
  }
}
void query(int l, int r, int o, const int& L, const int& R, mat& f) {
  if (L <= l && r <= R)
    f = f * d[o];
  else {
    const int mid = l + r >> 1;
    if (L <= mid) query(l, mid, o << 1, L, R, f);
    if (mid < R) query(mid + 1, r, o << 1 | 1, L, R, f);
  }
}
void pow(mat a, long long b, mat& f) {
  for (; b; b >>= 1, a = a * a)
    if (b & 1) f = f * a;
}
int main() {
  scanf("%lld%d%d", &k, &md, &n);
  for (int i = 0; i < n; ++i) scanf("%d", s + i), s[i] %= md;
  s[n] = *s;
  f = mat(0, 1, 0, 0);
  build(1, n, 1);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) scanf("%lld%d", &B[i].x, &B[i].v), B[i].v %= md;
  sort(B + 1, B + m + 1);
  for (int i = 1; i <= m; ++i)
    if (B[i].x <= k) {
      if (i == 1 || B[i].x != B[i - 1].x + 1)
        vec.push_back(
            make_pair(B[i].x, mat(0, s[(B[i].x - 1) % n], 1, B[i].v)));
      else
        vec.back().second.A[1][1] = B[i].v;
      if (B[i].x + 1 <= k)
        vec.push_back(
            make_pair(B[i].x + 1, mat(0, B[i].v, 1, s[(B[i].x + 1) % n])));
    }
  int it = 0;
  for (long long nw = 0; nw != k;) {
    long long nxt = (it == vec.size() ? k : vec[it].first - 1);
    if (nw / n != nxt / n) {
      int m = nw % n + 1;
      query(1, n, 1, m, n, f);
      nw = nw - (nw % n) + n;
      if (nw / n != nxt / n) pow(d[1], nxt / n - nw / n, f), nw = nxt / n * n;
    }
    if (nxt % n) query(1, n, 1, nw % n + 1, nxt % n, f);
    nw = nxt;
    if (nw == k) break;
    f = f * vec[it++].second;
    ++nw;
  }
  printf("%d\n", f[0][0]);
  return 0;
}
