#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x * 10) + (s & 15);
    s = getchar();
  }
  x *= f;
}
const int maxn = 5e4 + 2;
struct matrix {
  long long a[2][2], use;
  matrix() {
    memset(a, 0, sizeof(a));
    use = 0;
  }
} Ans, all, now, mul[maxn], b[maxn];
long long k, p, n, s[maxn], m, len, cpos, cval, cnt, npos, end, LEN;
struct opt {
  long long pos, ch, tag;
} op[maxn * 3];
inline bool cmp(opt a, opt b) { return a.pos < b.pos; }
inline void add(long long &a, long long b) { (a += b) %= p; }
inline void push(long long pos, long long ch, long long tag) {
  op[++cnt].pos = pos;
  op[cnt].ch = ch;
  op[cnt].tag = tag;
}
inline matrix operator*(matrix a, matrix b) {
  matrix tmp;
  for (long long i = 0; i <= 1; i++)
    for (long long j = 0; j <= 1; j++)
      for (long long k = 0; k <= 1; k++)
        add(tmp.a[i][j], a.a[i][k] * b.a[k][j]);
  return tmp;
}
inline matrix ksm(matrix a, long long b) {
  matrix ans;
  for (long long i = 0; i <= 1; i++) ans.a[i][i] = 1;
  for (; b; b >>= 1, a = a * a)
    if (b & 1) ans = ans * a;
  return ans;
}
struct Segment_Tree {
  matrix val[maxn << 2];
  inline void pushup(long long rt) {
    val[rt] = val[rt << 1] * val[rt << 1 | 1];
  }
  inline void insert(long long rt, long long l, long long r, long long k,
                     long long ch1, long long ch2) {
    if (l == r) {
      (val[rt].a[0][0] = ch1, val[rt].a[1][0] = ch2, val[rt].a[0][1] = 1);
      if (!mul[k].use) mul[k] = val[rt], b[k] = val[rt], mul[k].use = 1;
      return;
    }
    if (k <= ((l + r) >> 1))
      insert(rt << 1, l, ((l + r) >> 1), k, ch1, ch2);
    else
      insert(rt << 1 | 1, ((l + r) >> 1) + 1, r, k, ch1, ch2);
    pushup(rt);
  }
  inline matrix query(long long rt, long long l, long long r, long long L,
                      long long R) {
    if (L > R) {
      matrix ans;
      for (long long i = 0; i <= 1; i++) ans.a[i][i] = 1;
      return ans;
    }
    if (L <= l && r <= R) return val[rt];
    matrix ans;
    for (long long i = 0; i <= 1; i++) ans.a[i][i] = 1;
    if (L <= ((l + r) >> 1))
      ans = ans * query(rt << 1, l, ((l + r) >> 1), L, R);
    if (R > ((l + r) >> 1))
      ans = ans * query(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
    return ans;
  }
} t;
long long lst;
inline void chg(long long ps, matrix INS) {
  t.insert(1, 1, n, ps, INS.a[0][0], INS.a[1][0]);
}
signed main() {
  read(k);
  read(p);
  read(n);
  for (long long i = 0; i <= n - 1; i++) read(s[i]), s[i] %= p;
  for (long long i = 1; i <= n - 1; i++) t.insert(1, 1, n, i, s[i], s[i - 1]);
  t.insert(1, 1, n, n, s[0], s[n - 1]);
  all = t.val[1];
  read(m);
  for (long long i = 1; i <= m; i++) {
    read(cpos);
    read(cval);
    cval %= p;
    push(cpos, cval, 0);
    push(cpos + 1, cval, 1);
  }
  std::sort(op + 1, op + cnt + 1, cmp);
  while (cnt && op[cnt].pos > k) cnt--;
  Ans.a[0][0] = 1;
  lst = 0;
  for (long long i = 1; i <= cnt; i = (++npos)) {
    long long nbk = (op[i].pos - 1) / n;
    while (npos < cnt && nbk == (op[npos + 1].pos - 1) / n) npos++;
    Ans = Ans * ksm(all, nbk - lst);
    lst = nbk;
    for (long long k = i; k <= npos; k++) {
      long long d = (op[k].pos - 1) % n + 1;
      b[d].a[op[k].tag][0] = op[k].ch;
      chg(d, b[d]);
    }
    if (nbk == (k / n)) break;
    Ans = Ans * t.val[1];
    lst = (nbk + 1);
    for (long long k = i; k <= npos; k++) {
      long long d = (op[k].pos - 1) % n + 1;
      b[d] = mul[d];
      chg(d, b[d]);
    }
  }
  long long LST = (k % n);
  Ans = Ans * ksm(all, (k / n) - lst);
  for (long long i = 1; i <= LST; i++) Ans = Ans * b[i];
  printf("%lld\n", Ans.a[0][1]);
}
