#include <bits/stdc++.h>
using namespace std;
int P;
long long K;
int n, m;
int s[50010];
struct Pos {
  long long pos;
  int val;
} p[50010];
bool cmp(Pos a, Pos b) { return a.pos < b.pos; }
struct M {
  long long a[2][2];
  M() { memset(a, 0, sizeof(a)); }
};
M operator*(const M& a, const M& b) {
  M ans;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 2; k++)
        ans.a[i][j] = (ans.a[i][j] + a.a[i][k] * b.a[k][j]) % P;
  return ans;
}
M I() {
  M ans;
  ans.a[0][0] = 1;
  ans.a[1][1] = 1;
  return ans;
}
M fpow(const M& a, long long b) {
  M ans = I(), t = a;
  while (b) {
    if (b & 1) ans = ans * t;
    t = t * t;
    b >>= 1;
  }
  return ans;
}
M A(long long a, long long b) {
  M ans;
  ans.a[0][0] = 0;
  ans.a[0][1] = a;
  ans.a[1][0] = 1;
  ans.a[1][1] = b;
  return ans;
}
M T[200010];
void build(int root, int l, int r) {
  if (l == r) {
    T[root] = A(s[(l - 1 + n) % n], s[l]);
    return;
  }
  int mid = (l + r) >> 1;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
  T[root] = T[root << 1] * T[root << 1 | 1];
  return;
}
M query(int root, int l, int r, int x, int y) {
  if (x > y) return I();
  if (x <= l && r <= y) return T[root];
  int mid = (l + r) >> 1;
  if (x <= mid) {
    if (y > mid)
      return query(root << 1, l, mid, x, y) *
             query(root << 1 | 1, mid + 1, r, x, y);
    return query(root << 1, l, mid, x, y);
  }
  return query(root << 1 | 1, mid + 1, r, x, y);
}
M calc(long long x, long long y) {
  y--;
  if (x > y) return I();
  if (x / n == y / n) return query(1, 0, n - 1, x % n, y % n);
  M ans = I();
  ans = ans * query(1, 0, n - 1, x % n, n - 1);
  ans = ans * fpow(query(1, 0, n - 1, 0, n - 1), y / n - x / n - 1);
  ans = ans * query(1, 0, n - 1, 0, y % n);
  return ans;
}
int main() {
  scanf("%I64d %d", &K, &P);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &s[i]), s[i] %= P;
  build(1, 0, n - 1);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%I64d %d", &p[i].pos, &p[i].val);
  sort(p + 1, p + m + 1, cmp);
  M S;
  S.a[0][0] = 0;
  S.a[0][1] = 1;
  long long now = 1;
  int cur = 1;
  if (K == 0 || K == 1) {
    printf("%I64d\n", K % P);
    return 0;
  }
  while (now < K && cur <= m) {
    S = S * calc(now, min(p[cur].pos, K));
    now = min(p[cur].pos, K);
    int x = s[(now - 1) % n];
    bool flag = true;
    while (now < K && cur <= p[cur].pos &&
           (p[cur - 1].pos + 1 == p[cur].pos || flag)) {
      flag = false;
      S = S * A(x, p[cur].val);
      x = p[cur].val;
      cur++;
      now++;
    }
    if (now == K) break;
    S = S * A(x, s[now % n]);
    now++;
  }
  S = S * calc(now, K);
  printf("%I64d\n", S.a[0][1]);
  return 0;
}
