#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <class I>
inline void gi(I &x) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') f = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= f;
}
template <class I>
inline void print(I x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::gi;
using io::print;
using io::putc;
const int Max_N(50050);
const int Max_M(50050);
struct qwq {
  long long int pos, v;
};
inline bool operator<(const qwq &a, const qwq &b) { return a.pos < b.pos; }
int N, M;
long long int K, MOD, S[Max_N];
qwq T[Max_M];
struct Matrix {
  void give(long long int a = 0LL, long long int b = 0LL, long long int c = 0LL,
            long long int d = 0LL) {
    s[0][0] = a, s[0][1] = b;
    s[1][0] = c, s[1][1] = d;
  }
  long long int s[2][2];
};
Matrix operator*(const Matrix &a, const Matrix &b) {
  Matrix c;
  c.give();
  for (int i = 0; i != 2; ++i)
    for (int j = 0; j != 2; ++j)
      for (int k = 0; k != 2; ++k)
        (c.s[i][j] += a.s[i][k] * b.s[k][j] % MOD) %= MOD;
  return c;
}
Matrix power(Matrix a, long long int n) {
  Matrix c;
  c.give(1LL, 0LL, 0LL, 1LL);
  while (n) {
    if (n & 1LL) c = c * a;
    a = a * a, n >>= 1LL;
  }
  return c;
}
struct node {
  int l, r, mid;
  Matrix mtx;
};
node segt[Max_N << 2];
void build_tree(int cur, int l, int r) {
  (segt[cur].l) = l, (segt[cur].r) = r, (segt[cur].mid) = l + ((r - l) >> 1);
  if (l == r) {
    if (l == 0)
      (segt[cur].mtx).give(0LL, 1LL, S[N - 2], S[N - 1]);
    else if (l == 1)
      (segt[cur].mtx).give(0LL, 1LL, S[N - 1], S[0]);
    else
      (segt[cur].mtx).give(0LL, 1LL, S[l - 2], S[l - 1]);
    return;
  }
  build_tree((cur << 1), l, (segt[cur].mid)),
      build_tree(((cur << 1) | 1), (segt[cur].mid) + 1, r),
      (segt[cur].mtx) = segt[((cur << 1) | 1)].mtx * segt[(cur << 1)].mtx;
}
Matrix query(int cur, int l, int r) {
  if ((segt[cur].l) == l && (segt[cur].r) == r) return (segt[cur].mtx);
  if (r <= (segt[cur].mid))
    return query((cur << 1), l, r);
  else if (l > (segt[cur].mid))
    return query(((cur << 1) | 1), l, r);
  else
    return query(((cur << 1) | 1), (segt[cur].mid) + 1, r) *
           query((cur << 1), l, (segt[cur].mid));
}
void init() {
  gi(K), gi(MOD);
  gi(N);
  for (int i = 0; i <= N - 1; ++i) gi(S[i]), S[i] %= MOD;
  gi(M);
  for (int i = 1; i <= M; ++i) gi(T[i].pos), gi(T[i].v), T[i].v %= MOD;
  sort(T + 1, T + 1 + M);
  while (M && T[M].pos >= K) --M;
  build_tree(1, 0, N - 1);
}
inline Matrix get(long long int a, long long int b) {
  if (a / N == b / N)
    return query(1, a % N, b % N);
  else
    return query(1, 0, b % N) * power(segt[1].mtx, b / N - a / N - 1LL) *
           query(1, a % N, N - 1);
}
int tot;
Matrix jl[Max_M * 3];
void work() {
  if (N == 1) {
    for (int i = 1; i <= K; ++i)
      if (T[i].pos == K) {
        print(T[i].v);
        return;
      }
    print(S[0]);
    return;
  }
  Matrix beg, Ans, temp;
  beg.give(0LL, 0LL, 1LL, 0LL);
  Ans.give(1LL, 0LL, 0LL, 1LL);
  if (K <= 1LL) {
    print(K);
    return;
  }
  long long int last(1LL);
  if (M == 0 || T[M].pos < K - 1LL)
    T[++M].pos = K - 1LL, T[M].v = S[(K - 1LL) % N];
  for (int i = 1; i <= M; ++i)
    if (i == 1 || T[i].pos - T[i - 1].pos > 1LL) {
      if (i != 1)
        jl[++tot].give(0LL, 1LL, T[i - 1].v, S[(T[i - 1].pos + 1LL) % N]),
            last = T[i - 1].pos + 2LL;
      if (last + 1LL <= T[i].pos) jl[++tot] = get(last + 1LL, T[i].pos);
      jl[++tot].give(0LL, 1LL, S[((T[i].pos - 1LL) % N + N) % N], T[i].v);
      last = T[i].pos + 1LL;
    } else {
      jl[++tot].give(0LL, 1LL, T[i - 1].v, T[i].v);
      last = T[i].pos + 1LL;
    }
  for (int i = tot; i >= 1; --i) Ans = Ans * jl[i];
  print((Ans * beg).s[1][0]);
}
int main() {
  init();
  work();
  return 0;
}
