#include <bits/stdc++.h>
using namespace std;
long long k, r, t;
int s[131072], L[131072 * 2], R[131072 * 2], n, m, P;
struct sx {
  long long x, y1, y2, z;
  sx operator*(const sx& b) {
    sx a = *this, c;
    c.x = (a.x * b.x + a.y2 * b.y1) % P;
    c.y1 = (a.y1 * b.x + a.z * b.y1) % P;
    c.y2 = (a.x * b.y2 + a.y2 * b.z) % P;
    c.z = (a.y1 * b.y2 + a.z * b.z) % P;
    return c;
  }
} a[131072 * 2], ww, ans;
struct pr {
  long long x;
  int y;
} w[131072];
inline bool cmp(pr x, pr y) { return x.x < y.x; }
sx q(int x, int l, int r) {
  if (L[x] == l && R[x] == r) return a[x];
  if (r <= R[x * 2]) return q(x * 2, l, r);
  if (l >= L[x * 2 + 1]) return q(x * 2 + 1, l, r);
  return q(x * 2, l, R[x * 2]) * q(x * 2 + 1, L[x * 2 + 1], r);
}
sx p(long long x) {
  if (x == 1) return a[1];
  sx rr = p(x / 2);
  rr = rr * rr;
  if (x & 1) rr = rr * a[1];
  return rr;
}
int main() {
  scanf("%I64d%d%d", &k, &P, &n);
  if (k == 0) {
    printf("0\n");
    return 0;
  }
  for (int i = (1); i <= (n); i++) scanf("%d", &s[i]);
  scanf("%d", &m);
  for (int i = (1); i <= (m); i++) {
    scanf("%I64d%d", &w[i].x, &w[i].y);
    w[i].x++;
    w[i].y %= P;
  }
  sort(w + 1, w + m + 1, cmp);
  for (int i = (1); i <= (n); i++) s[i] %= P;
  for (int i = (1); i <= (131072); i++) {
    a[i + 131072 - 1].x = 1;
    a[i + 131072 - 1].z = 1;
    L[i + 131072 - 1] = i;
    R[i + 131072 - 1] = i;
  }
  for (int i = (1); i <= (n); i++) {
    a[i + 131072 - 1].x = 0;
    a[i + 131072 - 1].z = s[i % n + 1];
    a[i + 131072 - 1].y1 = 1;
    a[i + 131072 - 1].y2 = s[i];
  }
  for (int i = (131072 - 1); i >= (1); i--) {
    L[i] = L[i * 2];
    R[i] = R[i * 2 + 1];
    a[i] = a[i * 2] * a[i * 2 + 1];
  }
  for (; w[m].x > k; m--) w[m].x = 0, w[m].y = 0;
  if (w[m].x != k) w[++m].x = k, w[m].y = s[(((k)-1) % n + 1)];
  ans.x = 1;
  ans.z = 1;
  for (int i = (1); i <= (m); i++) {
    r = (w[i].x - 3) / n - (w[i - 1].x) / n;
    if (i > 1) {
      if (w[i].x == w[i - 1].x + 1) {
        ww.x = 0;
        ww.z = w[i].y;
        ww.y1 = 1;
        ww.y2 = w[i - 1].y;
        ans = ans * ww;
        continue;
      }
      ww.x = 0;
      ww.y1 = 1;
      ww.y2 = w[i - 1].y;
      ww.z = s[(((w[i - 1].x + 1) - 1) % n + 1)];
      ans = ans * ww;
    }
    if (r > 0) ans = ans * q(1, (((w[i - 1].x + 1) - 1) % n + 1), n);
    if (r > 1) ans = ans * p(r - 1);
    if (w[i - 1].x + 2 <= w[i].x - 1)
      if (r <= 0)
        ans = ans * q(1, (((w[i - 1].x + 1) - 1) % n + 1),
                      (((w[i].x - 2) - 1) % n + 1));
      else
        ans = ans * q(1, 1, (((w[i].x - 2) - 1) % n + 1));
    ww.x = 0;
    ww.y1 = 1;
    ww.y2 = s[(((w[i].x - 1) - 1) % n + 1)];
    ww.z = w[i].y;
    ans = ans * ww;
  }
  printf("%I64d\n", ans.z);
}
