#include <bits/stdc++.h>
using namespace std;
const int N = 50000 + 10;
long long rd() {
  long long x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int mod;
struct matrix {
  int a[2][2];
  matrix() { memset(a, 0, sizeof(a)); }
  matrix operator*(const matrix &bb) const {
    matrix an;
    for (int i = 0; i <= 1; ++i)
      for (int j = 0; j <= 1; ++j)
        an.a[i][j] =
            (1ll * a[i][0] * bb.a[0][j] + 1ll * a[i][1] * bb.a[1][j]) % mod;
    return an;
  }
} aa, bb[N][60], trn;
int n, m;
long long kk, a[N];
struct node {
  long long p, x;
  bool operator<(const node &bb) const { return p < bb.p; }
} ps[N];
int main() {
  kk = rd(), mod = rd(), n = rd();
  for (int i = 0; i < n; ++i) a[i] = rd();
  m = rd();
  bool fg = 0;
  for (int i = 1; i <= m; ++i) {
    ps[i].p = rd(), ps[i].x = rd();
    fg |= ps[i].p == kk;
  }
  if (!fg) ps[++m].p = kk, ps[m].x = a[kk % n];
  sort(ps + 1, ps + m + 1);
  while (ps[m].p > kk) --m;
  if (ps[m].p <= 1) {
    printf("%lld\n", ps[m].p % mod);
    return 0;
  }
  for (int i = 0; i < n; ++i)
    bb[i][0].a[0][1] = 1, bb[i][0].a[0][0] = a[i],
    bb[i][0].a[1][0] = a[(i + n - 1) % n];
  for (int j = 1; j <= 59; ++j)
    for (int i = 0; i < n; ++i)
      bb[i][j] = bb[i][j - 1] * bb[(1ll * i + (1ll << (j - 1))) % n][j - 1];
  long long np = 1;
  aa.a[0][0] = 1;
  ps[0].p = -1, ps[m + 1].p = kk + 1;
  for (int i = 1; i <= m; ++i) {
    for (int j = 59; ~j; --j)
      if (np + (1ll << j) <= ps[i].p) aa = aa * bb[np % n][j], np += 1ll << j;
    trn.a[0][1] = 1, trn.a[0][0] = ps[i].x,
    trn.a[1][0] =
        ps[i - 1].p == ps[i].p - 1 ? ps[i - 1].x : a[(np + n - 1) % n];
    aa = aa * trn, ++np;
    if (ps[i + 1].p == ps[i].p + 1) continue;
    trn.a[0][1] = 1, trn.a[0][0] = a[np % n], trn.a[1][0] = ps[i].x;
    aa = aa * trn, ++np;
  }
  printf("%d\n", aa.a[0][1]);
  return 0;
}
