#include <bits/stdc++.h>
using namespace std;
long long n;
int mod, m, dl, s[50010];
struct chan {
  long long j;
  int flag;
  int v;
  chan(long long j1 = 0, int flag1 = 0, int v1 = 0) {
    j = j1, flag = flag1, v = v1;
  }
  bool operator<(const chan &b) const { return j < b.j; }
} q[100010];
struct node {
  int a[2][2];
  node(int a_11 = 0, int a_12 = 0, int a_21 = 0, int a_22 = 0) {
    a[0][0] = a_11, a[0][1] = a_12, a[1][0] = a_21, a[1][1] = a_22;
  }
  node operator*(const node &b) const {
    node tmp;
    for (int i = 0; i < 2; i++)
      for (int k = 0; k < 2; k++)
        for (int j = 0; j < 2; j++)
          tmp.a[i][j] = (tmp.a[i][j] + 1ll * a[i][k] * b.a[k][j]) % mod;
    return tmp;
  }
  void print() {
    for (int i = 0; i < 2; i++, printf("\n"))
      for (int j = 0; j < 2; j++) printf("%d ", a[i][j]);
  }
} tree[200010], re[200010], ans(0, 1, 0, 0);
node ksm(node a, long long k) {
  node ans(1, 0, 0, 1);
  if (k < 0) return ans;
  for (; k; k >>= 1, a = a * a)
    if (k & 1) ans = ans * a;
  return ans;
}
void build(int l, int r, int t) {
  if (l == r) {
    tree[t] = re[t] = node(0, s[l - 1], 1, s[l % m]);
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, t << 1);
  build(mid + 1, r, t << 1 | 1);
  tree[t] = tree[t << 1] * tree[t << 1 | 1];
  re[t] = re[t << 1] * re[t << 1 | 1];
}
node query(int ll, int rr, int l, int r, int t) {
  if (ll <= l && r <= rr) return tree[t];
  int mid = (l + r) >> 1;
  if (mid >= rr) return query(ll, rr, l, mid, t << 1);
  if (mid < ll) return query(ll, rr, mid + 1, r, t << 1 | 1);
  return query(ll, rr, l, mid, t << 1) * query(ll, rr, mid + 1, r, t << 1 | 1);
}
void change(int a, int l, int r, int t, int w, int c) {
  if (l == r) {
    tree[t].a[w][1] = c;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= a)
    change(a, l, mid, t << 1, w, c);
  else
    change(a, mid + 1, r, t << 1 | 1, w, c);
  tree[t] = tree[t << 1] * tree[t << 1 | 1];
}
void Re(int a, int l, int r, int t) {
  if (l == r) {
    tree[t] = re[t];
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= a)
    Re(a, l, mid, t << 1);
  else
    Re(a, mid + 1, r, t << 1 | 1);
  tree[t] = tree[t << 1] * tree[t << 1 | 1];
}
int main() {
  scanf("%lld %d", &n, &mod);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d", &s[i]);
  build(1, m, 1);
  scanf("%d", &dl);
  for (int i = 1, v; i <= dl; i++) {
    long long j;
    scanf("%lld %d", &j, &v);
    q[i * 2 - 1] = chan(j, 1, v);
    q[i * 2] = chan(j + 1, 0, v);
  }
  dl <<= 1;
  sort(q + 1, q + dl + 1);
  long long lst_l = 1 - m, lst_r = 0;
  for (int i = 1, j = 1; i <= dl; i = j + 1, j = i) {
    long long now_l = ((q[i].j - 1) / m) * m + 1, now_r = now_l + m - 1;
    if (q[i].j > n) break;
    ans = ans * ksm(re[1], (now_l - lst_l) / m - 1);
    while (q[j + 1].j <= now_r && j < dl) j++;
    for (int k = i; k <= j; k++) {
      change((q[k].j - 1) % m + 1, 1, m, 1, q[k].flag, q[k].v);
    }
    if (now_r >= n) {
      ans = ans * query(1, (n - 1) % m + 1, 1, m, 1);
      lst_r = n;
    } else
      ans = ans * tree[1];
    for (int k = i; k <= j; k++) Re((q[k].j - 1) % m + 1, 1, m, 1);
    lst_l = now_l, lst_r = now_r;
  }
  if (lst_r < n) {
    long long now_l = ((n - 1) / m) * m + 1;
    ans = ans * ksm(re[1], (now_l - lst_l) / m - 1);
    ans = ans * query(1, (n - 1) % m + 1, 1, m, 1);
  }
  printf("%d\n", ans.a[0][0]);
}
