#include <bits/stdc++.h>
using namespace std;
long long K, n, m, mod, a[50050];
struct mart {
  long long a[2][2];
  mart() { memset(a, 0, sizeof a); }
  void clear() { memset(a, 0, sizeof a); }
  mart(long long x, long long y, long long z, long long w) {
    a[0][0] = x;
    a[0][1] = y;
    a[1][0] = z;
    a[1][1] = w;
  }
  mart operator*(mart B) {
    mart C;
    C.a[0][0] = (a[0][0] * B.a[0][0] + a[0][1] * B.a[1][0]) % mod;
    C.a[0][1] = (a[0][0] * B.a[0][1] + a[0][1] * B.a[1][1]) % mod;
    C.a[1][0] = (a[1][0] * B.a[0][0] + a[1][1] * B.a[1][0]) % mod;
    C.a[1][1] = (a[1][0] * B.a[0][1] + a[1][1] * B.a[1][1]) % mod;
    return C;
  }
  void print() {
    printf("%lld %lld\n%lld %lld\n\n", a[0][0], a[0][1], a[1][0], a[1][1]);
  }
} mat[50050 << 2], A, dan = mart(1, 0, 0, 1);
mart qp(mart a, long long b) {
  mart c = dan;
  while (b) {
    if (b & 1) c = c * a;
    a = a * a;
    b >>= 1;
  }
  return c;
}
void build(long long rt, long long l, long long r) {
  if (l == r) {
    mat[rt] = mart(a[l == n ? 0 : l], 1, a[l - 1], 0);
    return;
  }
  long long mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  mat[rt] = mat[rt << 1] * mat[rt << 1 | 1];
}
mart query(long long rt, long long l, long long r, long long x, long long y) {
  if (x > y) return dan;
  if (x <= l && r <= y) return mat[rt];
  long long mid = (l + r) >> 1;
  if (y <= mid) return query(rt << 1, l, mid, x, y);
  if (x > mid) return query(rt << 1 | 1, mid + 1, r, x, y);
  return query(rt << 1, l, mid, x, y) * query(rt << 1 | 1, mid + 1, r, x, y);
}
struct data {
  long long x, v;
} d[50050];
bool cmp(data a, data b) { return a.x < b.x; }
long long vis[50050], b[50050], tot;
long long fir, sec, fir_flag, sec_flag;
signed main() {
  scanf("%lld%lld", &K, &mod);
  if (K == 0) {
    puts("0");
    return 0;
  }
  if (K == 1) {
    if (mod == 1)
      puts("0");
    else
      puts("1");
    return 0;
  }
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++) scanf("%lld", &a[i]), a[i] %= mod;
  build(1, 1, n);
  scanf("%lld", &m);
  for (long long i = 1, x, v; i <= m; i++) {
    scanf("%lld%lld", &x, &v);
    if (x < n || x >= K) continue;
    d[++tot].x = x;
    d[tot].v = v % mod;
  }
  d[++tot].x = K;
  d[tot].v = 0;
  sort(d + 1, d + tot + 1, cmp);
  A = mart(1, 0, 0, 0);
  long long T = 0, t, l, r;
  for (long long i = 1; i <= tot; i++) {
    t = ((d[i].x - 2) / n) + 1;
    long long ii = i;
    while (ii <= tot && (d[ii].x - 2) / n + 1 == t) {
      vis[(d[ii].x) % n] = t;
      b[(d[ii].x) % n] = d[ii].v;
      ii++;
    }
    ii--;
    if (t != T + 1) {
      A = A * mart(fir_flag ? fir : a[1], 1, sec_flag ? sec : a[0], 0), l = 1;
      A = A * mart(a[2 % n], 1, fir_flag ? fir : a[1], 0), l = 2;
      A = A * query(1, 1, n, 3, n);
      fir_flag = sec_flag = 0;
      A = A * qp(mat[1], t - T - 2);
    }
    l = 1;
    r = ((d[i].x) % n - 1 + n) % n;
    if (!r) r = n;
    A = A * mart(fir_flag ? fir : a[1], 1, sec_flag ? sec : a[0], 0);
    l = 2;
    if (l <= r || d[i].x != K)
      A = A * mart(vis[2 % n] == t ? b[2 % n] : a[2 % n], 1,
                   fir_flag ? fir : a[1], 0),
      l = 3;
    while (i <= ii) {
      r = ((d[i].x) % n - 1 + n) % n;
      if (!r) r = n;
      if (l > r) {
        i++;
        continue;
      }
      if ((d[i - 1].x - 2) / n + 1 == t) {
        if (l <= r)
          A = A * mart(vis[(l) % n] == t ? b[(l) % n] : a[(l) % n], 1,
                       vis[(l - 1 + n) % n] == t ? b[(l - 1 + n) % n]
                                                 : a[(l - 1 + n) % n],
                       0),
          l++;
        if (l <= r)
          A = A * mart(vis[(l) % n] == t ? b[(l) % n] : a[(l) % n], 1,
                       vis[(l - 1 + n) % n] == t ? b[(l - 1 + n) % n]
                                                 : a[(l - 1 + n) % n],
                       0),
          l++;
      }
      A = A * query(1, 1, n, l, r);
      l = r + 1;
      i++;
    }
    T = t;
    i--;
    if (d[i].x != K) {
      if (l <= n)
        A = A * mart(vis[l % n] == t ? b[l % n] : a[l % n], 1,
                     vis[(l - 1 + n) % n] == t ? b[(l - 1 + n) % n]
                                               : a[(l - 1 + n) % n],
                     0),
        l++;
      if (l <= n)
        A = A * mart(vis[l % n] == t ? b[l % n] : a[l % n], 1,
                     vis[(l - 1 + n) % n] == t ? b[(l - 1 + n) % n]
                                               : a[(l - 1 + n) % n],
                     0),
        l++;
      A = A * query(1, 1, n, l, n);
    }
    if (d[i].x == t * n + 1)
      fir_flag = 1, fir = d[i].v;
    else
      fir_flag = 0;
    if (d[i].x == t * n)
      sec_flag = 1, sec = d[i].v;
    else if (d[i - 1].x == t * n)
      sec_flag = 1, sec = d[i - 1].v;
    else
      sec_flag = 0;
  }
  printf("%lld\n", A.a[0][0]);
  return 0;
}
